如何通过Curl和PHP发送SOAP XML?

这已经困扰了我好几天了;我正在尝试通过Curl发送SOAP帖子,但是我一直收到“无法连接到主机”错误,但是,我真的看不到如何。

我有一个ASP版本,可以在相同的URL和数据下正常工作。我认为这只是PHP / Curl的事情。

我目前有以下代码(CURLOPT_POSTFIELDS数据是有效的SOAP信封字符串):

$soap_do = curl_init();

curl_setopt($soap_do, CURLOPT_URL, "https://xxx.yyy.com:517/zzz.asmx" );

curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);

curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);

curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );

curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($soap_do, CURLOPT_POST, true );

curl_setopt($soap_do, CURLOPT_POSTFIELDS, '<soap:Envelope>...</soap:Envelope>');

curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen('<soap:Envelope>...</soap:Envelope>') ));

if(curl_exec($soap_do) === false)

{

$err = 'Curl error: ' . curl_error($soap_do);

curl_close($soap_do);

return $err;

}

else

{

curl_close($soap_do);

return 'Operation completed without any errors';

}

那么有什么想法为什么总是会出错?

ASP版本工作正常!代码是:

Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")

xmlhttp.Open "POST","https://xxx.yyy.com:517/zzz.asmx"

xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"

xmlhttp.Send('<soap:Envelope>...</soap:Envelope>')

回答:

非常感谢,您的代码对我有用。

这是代码:

$soap_do = curl_init(); 

curl_setopt($soap_do, CURLOPT_URL, $url );

curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);

curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);

curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );

curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($soap_do, CURLOPT_POST, true );

curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);

curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));

curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);

$result = curl_exec($soap_do);

$err = curl_error($soap_do);

以上是 如何通过Curl和PHP发送SOAP XML? 的全部内容, 来源链接: utcz.com/qa/423228.html

回到顶部