如何使用 NuSOAP 客户端启用 WS-RM(版本 1.2)



我可以像下面一样启用我使用 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'。(肥皂客户端>响应包含响应的内容(

如果有人正在寻找我上述问题的答案,我在@Marcel的帮助下找到了解决方案。

问题的答案:

这段代码是错误的,不要使用它。

$client = new nusoap_client($api_link, array('reliable' => 1.2 , 'useWSA' => TRUE) );

NuSoap 客户端已过时,不支持 WS-RM。我不得不使用PHP内置的SOAP扩展来使我的项目正常工作。

完整答案在这里:PHP 中的 SOAP 错误:操作格式化程序遇到无效的消息正文

谢谢

最新更新