开发者

HTTP Request with PHP + NuSoap

开发者 https://www.devze.com 2023-03-01 12:13 出处:网络
I\'m trying to create a http request to our web service, my test XML works when directly inputted into the we开发者_高级运维bservices test input field and I click \"Invoke\", but when trying to use th

I'm trying to create a http request to our web service, my test XML works when directly inputted into the we开发者_高级运维bservices 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. ---&gt; 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. :/


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号