编程语言
首页 > 编程语言> > soap:Envelope SOAP-ENV:Envelope PHP

soap:Envelope SOAP-ENV:Envelope PHP

作者:互联网

我正在尝试使用PHP的内置soap功能登录API.我得到了这样的结果.

[LoginResult]=> false,
[ErrorMsg] => Login failed with the reason : The security object is invalid

这是API提供商所要求的.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
    <Login xmlns="http://tempuri.org/Example/Service1">
          <objSecurity>
              <WebProviderLoginId>test</WebProviderLoginId>
              <WebProviderPassword>test</WebProviderPassword>
              <IsAgent>false</IsAgent>
          </objSecurity>
          <OutPut />
          <ErrorMsg />
    </Login>
</soap:Body>
</soap:Envelope>

&,这是我能够使用函数生成的.

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/Example/Service1">
<SOAP-ENV:Body>
    <ns1:Login>
        <objSecurity>
             <WebProviderLoginId>test</WebProviderLoginId>
             <WebProviderPassword>test</WebProviderPassword>
             <IsAgent>false</IsAgent>
        </objSecurity>
        <OutPut/>
        <ErrorMsg/>
    </ns1:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是我用来发送请求的代码.

<?php
class objSecurity {
function objSecurity($s, $i, $f)   {
    $this->WebProviderLoginId = $s;
    $this->WebProviderPassword = $i;
    $this->IsAgent = $f;
}
}

class nextObject {
function nextObject($objSecurity)   {
    $this->objSecurity=$pobjSecurity;
    $this->OutPut=NULL;
    $this->ErrorMsg=NULL;
}
}

$url    = 'http://example.com/sampleapi/test.asmx?WSDL';
$client = new SoapClient($url, array("soap_version" => SOAP_1_1,"trace" => 1));
$struct = new objSecurity('test', 'test', false);
$data   = new nextObject($struct);
$soapstruct2 = new SoapVar($data, SOAP_ENC_OBJECT);
print_r(
   $client->__soapCall(
       "Login",
       array(new SoapParam($soapstruct2, "inputStruct"))
   )
);

echo $client->__getLastRequest();

?>

这些是我发现的差异.

在我的请求xmlns:缺少xsi.

要求以< soap:Envelope开头,但我的请求以< SOAP-ENV:Envelope开头. 我的请求中有一个额外的xmlns:ns1. &安培;函数名称标记以ns1:开头. 请帮我把我的请求变成所需的格式. 我不太了解SOAP,我使用PHP版本5.3.13和CakePHP 2.3.0.对不起,我的英语不好.

解决方法:

这是解决方案.

标签:php,xml,soap,soap-client
来源: https://codeday.me/bug/20191001/1838517.html