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