我需要在PHP中使用Web服務https://www.example.com/example.svc?wsdl。爲此,我使用PHP SOAP客戶端。代碼段象下面這樣:PHP SOAP客戶端http頭錯誤
$client = new SoapClient("https://www.example.com/example.svc?wsdl",
array('soap_version' => SOAP_1_2,
'location'=>'https://www.example.com/example.svc',
'login'=> '#####',
'password'=> '#######',
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'encoding'=>'UTF-8',
'connection_timeout' => 500,
'keep_alive' =>false));
$client->__call('getProductList',array());
然而,當我運行這個它通過以下錯誤:
Warning: SoapClient::__doRequest(): SSL: The operation completed successfully. in E:\location\test1.php on line 37
Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in E:\location\test1:37 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://travius...', 'Travius/ITraviu...', 2, 0) #1 E:\location\test1(37): SoapClient->__call('getProductList', Array) #2 {main} thrown in E:\location\test1.php on line 37
我奮力幾天的時間來解決錯誤,但無法弄清楚。我嘗試了不同的解決方案,像堆棧溢出'keep_alive' =>false
,connection_timeout
但沒有任何效果。
我也嘗試使用php nusoap庫。它的請求和響應就像下面:
Error
HTTP Error: Unsupported HTTP response status 400 Bad Request (soapclient->response has contents of the response)
Request
POST /#####.svc?wsdl HTTP/1.0
Host: #####.#####.eu
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: application/soap+xml;charset=UTF-8; charset=UTF-8
SOAPAction: ""
Authorization: Basic RGVtb2FwaTpEdXE1dmRWdA==
Content-Length: 529
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><GetProduct><parameters><intProductID xsi:type="xsd:int">1266</intProductID><lang xsi:type="xsd:string">CN</lang></parameters></GetProduct></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response
HTTP/1.1 400 Bad Request
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 02 Oct 2017 16:03:04 GMT
Content-Length: 0
請注意,此Web服務在.NET應用程序工作正常。 任何幫助高度讚賞。提前致謝。
請詳細說明「MySoapClient」的來源以及引發此錯誤的實際WSDL。根據錯誤,它看起來像你使用nusoap,一般來說工作正常。 – jwriteclub
你應該嘗試使用本機php soapclient,看看它是否有幫助。您可以按照https://stackoverflow.com/questions/29934167/set-up-php-soap-extension-in-windows上的指南進行操作,它應該很容易測試。 – ksoni
你也可以看到有些用戶發現nusoap連接到C#(.Net)的問題https://stackoverflow.com/questions/15402233/which-is-better-php-soap-or-nusoap#comment54533941_15402304 – ksoni