【发布时间】:2015-09-09 16:42:38
【问题描述】:
所以我需要与 SOAP API 交互,我通过 curl 使用以下函数发送我的肥皂消息
/**
* @param $soap_msg
* @return int
*/
function send($soap_msg)
{
//init curl
$ch = curl_init();
//set some debug
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, true);
//set request method
curl_setopt($ch, CURLOPT_POST, true);
//set some other options
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, true);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
//set auth info
$username = 'user';
$password = '%PASS$';
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
//build header array
$headers = array();
$headers[] = 'Content-Type: application/soap+xml; charset=utf-8';
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Expect: 100-continue';
$headers[] = 'SOAPAction: http://ACTION/URL';
$headers[] = "Content-length: ".strlen($soap_msg);
//set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//set payload
curl_setopt($ch, CURLOPT_POSTFIELDS, $soap_msg);
//set soap resource
curl_setopt($ch, CURLOPT_URL, 'https://SOME.URL.co.uk/SERVICE.svc/detail');
//execute request
curl_exec($ch);
$info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $info;
}
echo send($soap_msg);
?>
传递的 SOAP 消息
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">http://my.action/endpoint/GetJob</a:Action>
<a:MessageID>urn:uuid:b7747707-97cc-4edf-9cb0-b8dd40f45509</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">https://my.webservice.co.uk/Appt/AppointWS/service.svc/detail</a:To>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2015-09-08T19:52:16.065Z</u:Created>
<u:Expires>2015-09-08T19:57:16.065Z</u:Expires>
</u:Timestamp>
<o:UsernameToken u:Id="uuid-2c7e3d75-b18d-480a-979e-57e6a042e9f2-2">
<o:Username>user</o:Username>
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">%pass$</o:Password>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body>
<GetJob xmlns="http://tempuri.org/">
<jobEntryId>630422258</jobEntryId>
<jobNo1>3874527</jobNo1>
<contractId>220000</contractId>
</GetJob>
</s:Body>
</s:Envelope>
回显输出给出 500 错误
我从上周为另一个运行良好的 SOAP 服务编写的函数中剥离了该函数的基础知识,所以我对问题所在感到有些困惑
编辑: 刚刚在 mac 'Restinsoap' 上的外部客户端中尝试过这个,我得到以下响应仍然是 500
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
<a:RelatesTo>urn:uuid:588e5592-c60a-4c2d-b643-c6af9c4772f5</a:RelatesTo>
</s:Header>
<s:Body>
<s:Fault>
<s:Code>
<s:Value>s:Sender</s:Value>
<s:Subcode>
<s:Value xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:InvalidSecurity</s:Value>
</s:Subcode>
</s:Code>
<s:Reason>
<s:Text xml:lang="en-GB">An error occurred when verifying security for the message.</s:Text>
</s:Reason>
</s:Fault>
</s:Body>
</s:Envelope>
但是如果我在 Windows 机器上的 wcfstorm 中执行请求就可以了
【问题讨论】:
标签: php web-services iis curl soap