使用 PHP 向 Soap Server 提交数据

发布于 2024-12-03 16:33:44 字数 3272 浏览 2 评论 0原文

我无法将标头传递给 WSDL 以获取凭证:

这是代码:

$soapClient = new SoapClient("https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL");
$header = array('user'=>'user1','pass'=>'pass1');
$soapClient->__setSoapHeaders(new SoapHeader("https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL",'SecHeader',$header));
$res = $soapClient->__call("Recipients_checkUnsubscribed", array('email'=> '[email protected]'));
var_dump($res);

我收到以下错误:

致命错误:未捕获 SoapFault 异常:[soap:Client] 请 提供安全标头...

这是 WSDL 描述: https:// www.em-sender.com/ws/InwiseWebServices.asmx?op=Recipients_checkUnsubscribed

或参见此处:

POST /ws/InwiseWebServices.asmx HTTP/1.1
Host: www.em-sender.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <SecHeader xmlns="http://www.inwise.com/schemas">
      <username>string</username>
      <pass>string</pass>
    </SecHeader>
    <AuthIdentifier xmlns="http://www.inwise.com/schemas">
      <identifier>string</identifier>
    </AuthIdentifier>
  </soap12:Header>
  <soap12:Body>
    <Recipients_checkUnsubscribed xmlns="http://www.inwise.com/schemas">
      <email>string</email>
    </Recipients_checkUnsubscribed>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <Recipients_checkUnsubscribedResponse xmlns="http://www.inwise.com/schemas">
      <Recipients_checkUnsubscribedResult>boolean</Recipients_checkUnsubscribedResult>
    </Recipients_checkUnsubscribedResponse>
  </soap12:Body>
</soap12:Envelope>

编辑

这是发送的字符串:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.inwise.com/schemas" xmlns:ns2="https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL"> 
<SOAP-ENV:Header> 
    <ns2:SecHeader> 
        <item> 
            <key>user</key> 
            <value>user1</value> 
        </item> 
        <item> 
            <key>pass</key> 
            <value>pass1</value> 
        </item> 
    </ns2:SecHeader> 
</SOAP-ENV:Header> 
<SOAP-ENV:Body> 
    <ns1:Recipients_checkUnsubscribed/> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

I am unable to pass the header to the WSDL for credencials:

this is the code:

$soapClient = new SoapClient("https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL");
$header = array('user'=>'user1','pass'=>'pass1');
$soapClient->__setSoapHeaders(new SoapHeader("https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL",'SecHeader',$header));
$res = $soapClient->__call("Recipients_checkUnsubscribed", array('email'=> '[email protected]'));
var_dump($res);

I am getting the following error:

Fatal error: Uncaught SoapFault exception: [soap:Client] Please
provide security header in...

this is the WSDL description: https://www.em-sender.com/ws/InwiseWebServices.asmx?op=Recipients_checkUnsubscribed

or see here:

POST /ws/InwiseWebServices.asmx HTTP/1.1
Host: www.em-sender.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <SecHeader xmlns="http://www.inwise.com/schemas">
      <username>string</username>
      <pass>string</pass>
    </SecHeader>
    <AuthIdentifier xmlns="http://www.inwise.com/schemas">
      <identifier>string</identifier>
    </AuthIdentifier>
  </soap12:Header>
  <soap12:Body>
    <Recipients_checkUnsubscribed xmlns="http://www.inwise.com/schemas">
      <email>string</email>
    </Recipients_checkUnsubscribed>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <Recipients_checkUnsubscribedResponse xmlns="http://www.inwise.com/schemas">
      <Recipients_checkUnsubscribedResult>boolean</Recipients_checkUnsubscribedResult>
    </Recipients_checkUnsubscribedResponse>
  </soap12:Body>
</soap12:Envelope>

Edit

This is the sent string:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.inwise.com/schemas" xmlns:ns2="https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL"> 
<SOAP-ENV:Header> 
    <ns2:SecHeader> 
        <item> 
            <key>user</key> 
            <value>user1</value> 
        </item> 
        <item> 
            <key>pass</key> 
            <value>pass1</value> 
        </item> 
    </ns2:SecHeader> 
</SOAP-ENV:Header> 
<SOAP-ENV:Body> 
    <ns1:Recipients_checkUnsubscribed/> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜是你 2024-12-10 16:33:44

我已经审查了您的 SOAP 请求,如果您进行精确比较,您会发现两个问题:

  1. 键/值对不好(应该是用户名和密码)
  2. 肥皂头的命名空间不正确。

如果我尝试以下操作,则会收到一条错误消息,告诉我的凭据无效,这是有道理的,因为我刚刚填写了一些内容。我不会再遇到安全标头错误了。

$soapClient = new SoapClient("https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL", array('trace' => true));
$header = new SoapVar(array('username' => 'user', 'pass' => 'password'), SOAP_ENC_OBJECT);
$soapClient->__setSoapHeaders(new SoapHeader("http://www.inwise.com/schemas",'SecHeader',$header));

try {
    $res = $soapClient->Recipients_checkUnsubscribed('[email protected]');
    var_dump($res);
} catch(SoapFault $fault) {
    var_dump($soapClient->__getLastRequest());
    var_dump($fault->getMessage());
}

I have reviewed your SOAP request, and if you exactly compare you can see two problems:

  1. The key/value pairs weren't okay (should be username and pass)
  2. The namespace of the soapheader was incorrect.

If I try the following then I get a error message telling my credentials are invalid which makes sense because I just filled in something. I won't get the security header fault anymore.

$soapClient = new SoapClient("https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL", array('trace' => true));
$header = new SoapVar(array('username' => 'user', 'pass' => 'password'), SOAP_ENC_OBJECT);
$soapClient->__setSoapHeaders(new SoapHeader("http://www.inwise.com/schemas",'SecHeader',$header));

try {
    $res = $soapClient->Recipients_checkUnsubscribed('[email protected]');
    var_dump($res);
} catch(SoapFault $fault) {
    var_dump($soapClient->__getLastRequest());
    var_dump($fault->getMessage());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文