【问题标题】:HTTP Request with PHP + NuSoap使用 PHP + NuSoap 的 HTTP 请求
【发布时间】:2011-06-13 21:58:47
【问题描述】:

我正在尝试为我们的 Web 服务创建一个 http 请求,我的测试 XML 在直接输入到 Web 服务测试输入字段并单击“调用”时可以工作,但是当尝试将相同的数据与 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 
?>

非常感谢任何见解和猜测。很长一段时间以来,我一直在用头撞砖墙。 :/

【问题讨论】:

  • 我可以从不需要参数/参数的内置 HelloWorld 方法获得成功的响应。

标签: php soap httprequest nusoap


【解决方案1】:

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

【讨论】:

  • 我以前试过这个,现在又一次,对我自己发送的数据进行 urlencoding 使 SOAP 请求被部分编码并部分与实体混淆 - 仍然给出错误。
【解决方案2】:

我不确定这是否对你有帮助,但请检查一下

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

【讨论】:

  • 在这种情况下有点矫枉过正,我不确定重做是否能解决实际问题。
【解决方案3】:

问题已经解决,实际上是由于错误的 ASP 代码期望只有空格被 html 编码,从而导致错误的响应。

【讨论】:

  • 我不明白空格是什么意思?
  • 空白字符,用于单词之间的空格的计算机字符。 Urlencode 等效为 %20
猜你喜欢
  • 1970-01-01
  • 2011-08-17
  • 2014-11-16
  • 2015-08-09
  • 1970-01-01
  • 2011-06-01
  • 1970-01-01
  • 2016-09-05
  • 2020-08-21
相关资源
最近更新 更多