0
這是SOAP請求無法使用PHP捲曲
<SOAP-ENV:Envelopexmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sas="http://api.testdemo.in/">
<SOAP-ENV:Body>
<sas:Login>
<Username>user</Username>
<Password>password</Password>
</sas:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我嘗試下面的下面的代碼的要求格式進行API調用,
$xml = '<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sas="http://api.testdemo.in/">
<SOAP-ENV:Body>
<sas:Login>
<Username>user</Username>
<Password>password</Password>
</sas:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
$url = "http://api.testdemo.in/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$headers = array();
array_push($headers, "Content-Type: text/xml; charset=utf-8");
array_push($headers, "Accept: text/xml");
array_push($headers, "Cache-Control: no-cache");
array_push($headers, "Pragma: no-cache");
if($xml != null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
array_push($headers, "Content-Length: " . strlen($xml));
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($response);
print_r($code);
本頁面加載了一段時間,我得到了'0'在頁面上。
實際的XML響應應該是
<SOAP-ENV:Envelopexmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sas="http://api.testdemo.in/">
<SOAP-ENV:Body>
<sas:LoginResponse>
<SessionID>FC82329EF6</SessionID>
<ResponseCode>0</ResponseCode>
<ResponseMessage>Successsful</ResponseMessage>
</sas:LoginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
進出口新的SOAP,不能找到一個更好的way..I得到了上面的代碼在網上,我不知道這是方式的SOAP請求應完成。
請建議一些方法可以做到it.Thanks傢伙
謝謝,我試過你的代碼,因爲'捲曲錯誤No28錯誤描述:30000毫秒後連接超時'。任何想法爲什麼會發生這種情況 – user3713664 2014-09-21 18:48:21
這是因爲cURL默認超時是30秒,請嘗試加上這個 curl_setopt($ ch,CURLOPT_TIMEOUT,500); //將curl超時設置爲500 curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,false); //停止無限重定向 – Ponce 2014-09-23 18:06:06