我有点亏本,没有永远触及一个肥皂脚本并且环顾一下stackoverflow和谷歌只是混淆了这个问题。 PHP.net示例似乎也过时了。
SOAP Request应该POST到非WSDL url。 https://some.soapurl.com/provided
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:cam="http://kamp.gw.com/kamp">
<soapenv:Header/>
<soapenv:Body>
<cam:setRolesUpdatedRequest>
<cam:orgCode>username</cam:orgCode>
<cam:password>password</cam:password>
<cam:emails>
<cam:email>abc@dom.com</cam:email>
<cam:email>def@dom.com</cam:email>
<cam:email>ghi@dom.com</cam:email>
</cam:emails>
<cam:updateAllUsers>false</cam:updateAllUsers>
</cam:setRolesUpdatedRequest>
</soapenv:Body>
</soapenv:Envelope>
只需运行此代码段即可返回200 OK标头,这很好。
try {
$client = new SoapClient("https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated");
}
catch(Exception $e)
{
$e->getMessage();
}
我希望得到的回应看起来像是
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:returnStatus xmlns:ns1="http://kamp.gw.com/kamp">
<ns1:type>S</ns1:type>
<ns1:desc>Successful</ns1:desc>
</ns1:returnStatus>
</soapenv:Body>
</soapenv:Envelope>
编辑:
我尝试使用curl版本直接发布xml字符串。
$post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cam="http://kamp.gw.com/kamp">
<soapenv:Header/>
<soapenv:Body>
<cam:setRolesUpdatedRequest>
<cam:orgCode>username</cam:orgCode>
<cam:password>password</cam:password>
<cam:emails>
<cam:email>abc@dom.com</cam:email>
<cam:email>def@dom.com</cam:email>
<cam:email>ghi@dom.com</cam:email>
</cam:emails>
<cam:updateAllUsers>false</cam:updateAllUsers>
</cam:setRolesUpdatedRequest>
</soapenv:Body>
</soapenv:Envelope>';
$user = "username";
$password = "password";
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($xml),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 100000);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 100000);
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, $headers); //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);
var_dump($result);
echo "<br /><br />";
var_dump($err);
但不幸的是结果是
bool(false)
string(74) "Failed connect to abc.kamp.group.com:443; Connection timed out"
我不确定这是我的错还是网络服务的错。即使我连接超时,返回的标题仍然是200 Ok。
答案 0 :(得分:0)
首先检查SOAP服务URL和访问凭据是否正常工作。使用SoapUI或类似工具发出独立于PHP SoapClient代码的请求。
同时检查拨打电话时是否存在任何IP地址限制,如果是,请创建/请求您发出请求的IP地址的例外。
如果检查完毕,请使用php.net SoapClient示例进行简单调用并构建脚本逻辑。
<?php
$client = new SoapClient('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl');
var_dump($client->__getFunctions());
?>
答案 1 :(得分:0)
Forgot i是代理的背后,一旦我指着curl到代理服务器,一切都很顺利。