【问题标题】:NuSOAP: how to change content-type of request?NuSOAP:如何更改请求的内容类型?
【发布时间】:2010-10-31 01:30:10
【问题描述】:

使用 .NET WCF 网络服务时,我收到以下响应(错误):

不支持的 HTTP 响应状态 415 无法处理消息,因为内容类型为 'text/xml;字符集=UTF-8' 不是预期的类型'application/soap+xml; charset=utf-8'。

如何更改内容类型?我在 NuSOAP 论坛/文档中找不到它,或者我可能忽略了某些东西....

【问题讨论】:

    标签: php web-services content-type nusoap


    【解决方案1】:

    我知道这是一篇旧帖子,但我跑到这个页面寻找答案。

    application/soap+xml 是使用 SOAP 1.2 时传递的内容类型, text/xml 与 SOAP 1.1 一起使用,

    这样的事情应该可以解决问题,

    $client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_1));
    

    【讨论】:

      【解决方案2】:

      您可以像这样使用 web 服务指定 NuSOAP 流的编码:

      $client = new nusoap_client($params);
      $client->soap_defencoding = 'UTF-8';
      

      【讨论】:

      • 哇,这很容易。谢谢!
      【解决方案3】:

      NuSOAP 库中似乎有一点遗漏...它假定内容标头必须是“text/xml”,因此如果您的客户端尝试连接到输出应用程序/soap+xml 标头的服务,您最终会遇到如下错误:

      不是文本/xml类型的响应:application/soap+xml;字符集=utf-8

      要对此进行测试,您可能会受益于以下我用来登录 SOAP 服务的小函数模式。请记住,打印出客户端对象!您实际上可能看不到结果!

      require_once('path/to/downloaded/libraries/nusoap.php');    
      var $endpoint = 'https://somedomain.com/path/to/soap/server/Login';
      var $client; // the soapclient object
      
      function SOAP_Login()
      {
          $this->client = new soapclient($this->endpoint);
      
          $err = $this->client->getError();
          if ($err) 
          {
              // Display the error
              echo '<p><b>SOAP Constructor error: ' . $err . '</b></p>';
              exit;
              // At this point, you know the call that follows will fail
          }
      
          $params = array( 
              'some' => 'thing.. depends on what the WSDL expects'
          );
      
          $result = $this->client->call('someFunction', $params);     
      
          print_r($result);  // Without the fix, this prints nothing (i.e. false) !!!
      
          print_r($this->client); // Instead, look at the state of the client object, specifically error_str and debug_str
      }
      

      当我打印 $result 时,我什么也没得到,但是当我打印 $client 对象时,我可以看到有错误。

      我实现的小技巧是在 nusoap.php 文件中,大约第 7500 行。寻找这个 if 语句:

      if (!strstr($headers['content-type'], 'text/xml')) {
          $this->setError('Response not of type text/xml: ' . $headers['content-type']);
          return false;
      }
      

      把它改成这样:

      if (!strstr($headers['content-type'], 'text/xml') && !strstr($headers['content-type'], 'application/soap+xml') ) {
          $this->setError('Response not of type text/xml: ' . $headers['content-type']);
          return false;
      }
      

      这一切只是让 NuSOAP 处理发出“application/soap+xml”标头(这是一个有效的 xml 标头)的响应。

      【讨论】:

        【解决方案4】:

        我也被困在这个问题上。

        秘密在 web.config 将 wsHttpBinding 更改为 basicHttpBinding

        像这样:

        <endpoint address="" binding="basicHttpBinding" contract="YourProject.View.Whatever.IYourService">
        

        希望对您有所帮助! /埃里克

        【讨论】:

        • 我无法将其更改为 basicHttpBinding,因为我们的证书需要 wsHttpBinding。
        【解决方案5】:

        这对我有用:

        $client = new nusoap_client($params);

        $client->soap_defencoding = 'UTF-8';

        勾选为正确的答案不适用于 NUSOAP,因此不是适当的答案。

        【讨论】:

          猜你喜欢
          • 2018-05-07
          • 2017-11-14
          • 2017-07-03
          • 2017-12-09
          • 2018-07-09
          • 1970-01-01
          • 2012-09-22
          • 2018-08-30
          • 1970-01-01
          相关资源
          最近更新 更多