我在应用程序Laravel中遇到问题,例如当我使用SoapClient时,例如my_object_soap->login();
返回了此错误:
致命错误:未捕获的SoapFault异常:[客户端]看起来我们没有XML
我已经尝试了一些在google和此处研究过的解决方案,但并没有解决我的问题。
我的代码如下:
ini_set("soap.wsdl_cache_enabled",0);
ini_set("soap.wsdl_cache",0);
ini_set("error_reporting",-1);
ini_set("display_errors","On");
$wsdl_url = "https://example.com/index.php/api/v2_soap/index/?wsdl";
$apiAuth = new \stdClass();
$apiAuth->username = trim("myusermagento");
$apiAuth->apiKey = trim("mykeymagento");
try{
$proxy = new SoapClient($wsdl_url,array('cache_wsdl' => WSDL_CACHE_NONE, 'trace' => true));
$session = $proxy->login($apiAuth);
$data = $session;
$status = true;
$responseStatus = 200;
} catch(SoapFault $e) {
$error = $e->getMessage();
$data = $proxy->__getLastResponse();
$status = false;
$responseStatus = 500;
}
return Response::json([
'success' => $status,
'data' => $data,
'erros'=> $error,
],$responseStatus);
我不知道哪个问题,当我在SoapUI中使用此用户和密钥进行测试时,没问题,但是在我的应用程序中没有。
我的magento版本应用程序是1.6.2,而我的php是7.2,我已经尝试降级到php 5.6,因为它可能与magento版本和我的php不兼容,但是仍然无法正常工作。
有人可以帮我吗?
答案 0 :(得分:0)
尝试一下,按如下所示构造您的请求
$options = array('trace'=> true,'exceptions' => true);
$client = new \SoapClient('https://www.example.com?wsdl',$options);
$params = new \stdClass();
$params->key1 = 'XXXXXX';
$params->Key2 = 'XXXXX';
$soapVar = new \SoapVar($params,SOAP_ENC_OBJECT);
$header = new \SoapHeader('https://www.example?wsdl','credentials',$soapVar);
$client->__setSoapHeaders(array($header));
$result=$client->login(function parameters here);
干杯!