使用 PHP 进行 HTTP 请求努肥皂

发布于 2024-11-03 20:10:32 字数 3902 浏览 1 评论 0 原文

我正在尝试创建对我们的 Web 服务的 http 请求,当直接输入到 Web 服务测试输入字段并单击“调用”时,我的测试 XML 可以正常工作,但是当尝试通过 PHP + NuSoap 使用相同的数据时,我得到了我无法解决的特殊错误,我尝试用谷歌搜索它,但没有显示与此案例相关的内容。

这是请求:

POST /iInterface_pc2/service.asmx HTTP/1.0
Host: 10.10.86.55
User-Agent: NuSOAP/0.9.6dev (1.137)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://www.xxxx.com.cn/TransferMaterialInfo"
Content-Length: 722

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
  <TransferMaterialInfo xmlns="http://www.xxxx.com.cn/">
    <Materiallist>
      <Materialinfo>
        <id>123456</id>
        <title>Hello word</title>
        <datetime>2011-04-23 12:12:12</datetime>
        <contributor>Some One</contributor>
        <materialurl>www.website.com/path/audio1.mp3</materialurl>
        <duration>10000</duration>
        <status>0</status>
        <remark></remark>
      </Materialinfo>
    </Materiallist>
  </TransferMaterialInfo>
</soap:Body>
</soap:Envelope>

和响应:

HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Thu, 28 Apr 2011 11:04:11 GMT
Connection: close
Content-Length: 428

<?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>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. ---&gt; Value cannot be null.
Parameter name: s</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>

最后是我用来生成请求的 PHP

<?php
      // include soap file
      require_once('lib/nusoap.php');

      // set end point
      $endpoint = "http://10.10.86.55/iInterface_pc2/service.asmx";

      // create client
      $client = new nusoap_client($endpoint);

      if ( $client->getError() ) {
        print "Soap Constructor Error: ";
        print_r($client->getError());
      }

      // Human readable
      $request = <<<HEREDOC

      <TransferMaterialInfo xmlns="http://www.xxxx.com.cn/">
        <Materiallist>
          <Materialinfo>
            <id>123456</id>
            <title>Hello word</title>
            <datetime>2011-04-23 12:12:12</datetime>
            <contributor>Some One</contributor>
            <materialurl>www.website.com/path/audio1.mp3</materialurl>
            <duration>10000</duration>
            <status>0</status>
            <remark></remark>
          </Materialinfo>
        </Materiallist>
      </TransferMaterialInfo>
    HEREDOC;

      $action  = "http://www.xxxx.com.cn/TransferMaterialInfo";

      $msg     = $client->serializeEnvelope($request, '', array(), 'document', 'encoded', '');
      $result  = $client->send($msg, $action);

      if ( $client->fault ) { //soap_fault
        print "Soap Fault :";
        print_r($client->fault->faultcode);
        print_r($client->fault->faultstring);
      }
      elseif ( $client->getError() ) {
        print "Soap Error :";
        print_r($client->getError());
      }
      else {
        print "Result: ";
        print_r($result);
      }

      ..print stuff 
?>

任何见解和猜测都非常感谢。我已经用头撞砖墙已经有一段时间了。 :/

I'm trying to create a http request to our web service, my test XML works when directly inputted into the webservices test input field and I click "Invoke", but when trying to use the same data with PHP + NuSoap, I get a peculiar error which I've been unable to solve, I've tried to google for it but nothing relevant shows up for this case.

Here is the Request:

POST /iInterface_pc2/service.asmx HTTP/1.0
Host: 10.10.86.55
User-Agent: NuSOAP/0.9.6dev (1.137)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://www.xxxx.com.cn/TransferMaterialInfo"
Content-Length: 722

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
  <TransferMaterialInfo xmlns="http://www.xxxx.com.cn/">
    <Materiallist>
      <Materialinfo>
        <id>123456</id>
        <title>Hello word</title>
        <datetime>2011-04-23 12:12:12</datetime>
        <contributor>Some One</contributor>
        <materialurl>www.website.com/path/audio1.mp3</materialurl>
        <duration>10000</duration>
        <status>0</status>
        <remark></remark>
      </Materialinfo>
    </Materiallist>
  </TransferMaterialInfo>
</soap:Body>
</soap:Envelope>

And the Response:

HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Thu, 28 Apr 2011 11:04:11 GMT
Connection: close
Content-Length: 428

<?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>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. ---> Value cannot be null.
Parameter name: s</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>

And finally the PHP I use to generate the request

<?php
      // include soap file
      require_once('lib/nusoap.php');

      // set end point
      $endpoint = "http://10.10.86.55/iInterface_pc2/service.asmx";

      // create client
      $client = new nusoap_client($endpoint);

      if ( $client->getError() ) {
        print "Soap Constructor Error: ";
        print_r($client->getError());
      }

      // Human readable
      $request = <<<HEREDOC

      <TransferMaterialInfo xmlns="http://www.xxxx.com.cn/">
        <Materiallist>
          <Materialinfo>
            <id>123456</id>
            <title>Hello word</title>
            <datetime>2011-04-23 12:12:12</datetime>
            <contributor>Some One</contributor>
            <materialurl>www.website.com/path/audio1.mp3</materialurl>
            <duration>10000</duration>
            <status>0</status>
            <remark></remark>
          </Materialinfo>
        </Materiallist>
      </TransferMaterialInfo>
    HEREDOC;

      $action  = "http://www.xxxx.com.cn/TransferMaterialInfo";

      $msg     = $client->serializeEnvelope($request, '', array(), 'document', 'encoded', '');
      $result  = $client->send($msg, $action);

      if ( $client->fault ) { //soap_fault
        print "Soap Fault :";
        print_r($client->fault->faultcode);
        print_r($client->fault->faultstring);
      }
      elseif ( $client->getError() ) {
        print "Soap Error :";
        print_r($client->getError());
      }
      else {
        print "Result: ";
        print_r($result);
      }

      ..print stuff 
?>

Any insights and guesses GREATLY appreciated. I've been banging my head against a brick wall for a good while now. :/

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

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

发布评论

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

评论(3

-柠檬树下少年和吉他 2024-11-10 20:10:32

我相信服务器正在看到 <和>字符并将其解码为 >
您可能需要在发送之前对数据进行 urlencode

I believe the server is seeing the < and > characters and decoding it to >
You may need to urlencode the data before sending

⊕婉儿 2024-11-10 20:10:32

我不确定这是否对您有帮助,但请以任何方式检查

http://mohammed-magdy.blogspot.com/2011/04/creating-web-services-using-php.html

i am not sure , if that will help you or not , but check it any way

http://mohammed-magdy.blogspot.com/2011/04/creating-web-services-using-php.html

倚栏听风 2024-11-10 20:10:32

该问题已解决,实际上是由错误的 ASP 代码导致的,该代码期望仅对空格进行 html 编码,从而导致错误的响应。

The problem has been solved and was actually caused by faulty ASP code expecting only whitespaces to be html-encoded, resulting in faulty response.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文