可以像下面那样使用 NuSOAP 客户端启用 WS-RM(1.2 版)吗?我试过了,但我无法从 API 接收数据。有任何想法吗?谢谢。
$client = new nusoap_client($api_link, array('reliable' => 1.2 , 'useWSA' => TRUE) );
完整代码:
try {
include_once 'WebServiceSOAP/lib/nusoap.php';
$api_link = 'https://www.my-api.com/MYAPI.svc/SSL?wsdl';
$acode = '###';
$uname = '###';
$ttype = '###';
$ccode = '###';
$hpass = '###';
//setting xml request to api
$credentials = '<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" xmlns:ezr="http://schemas.datacontract.org/2004/07/EzremitAPI.Entities">
<soapenv:Header/>
<soapenv:Body>
<tem:GetLocalRates>
<!--Optional:-->
<tem:credentials>
<!--Optional:-->
<ezr:AgentCode>'.$acode.'</ezr:AgentCode>
<!--Optional:-->
<ezr:HashedPassword>'.$hpass.'</ezr:HashedPassword>
<!--Optional:-->
<ezr:Username>'.$uname.'</ezr:Username>
</tem:credentials>
<!--Optional:-->
<tem:payincurcode>'.$ccode.'</tem:payincurcode>
<!--Optional:-->
<tem:transferType>'.$ttype.'</tem:transferType>
</tem:GetLocalRates>
</soapenv:Body>
</soapenv:Envelope>';
//creating soap object
$client = new nusoap_client($api_link, array('cache_wsdl' => WSDL_CACHE_NONE, 'soap_version' => SOAP_1_2) );
$client->soap_defencoding = 'UTF-8';
$soapaction = "http://tempuri.org/IRateAPI/GetLocalRates";
$xmlobjs = $client->send($credentials, $soapaction);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
exit();
}
//print_r($client);
print_r($xmlobjs);
}
catch(Exception $e) {
echo $e->getMessage();
}
?>
我不太擅长 PHP 和 SOAP。以上代码可能有错误。请您检查代码并给我您的意见。我在谷歌搜索后做了一些修改。
另外,我可以在 PHP 5.4.42 上运行它吗?当我运行上面的代码时,我现在得到以下错误。
构造函数错误 HTTP 错误:不支持的 HTTP 响应状态 415 无法处理消息,因为内容类型为 'text/xml; charset=UTF-8' 不是预期的类型 'application/soap+xml; 字符集=utf-8'。(soapclient->response 有响应的内容)