【问题标题】:PHP SoapClient Cannot process the message because the content type 'text/xml;PHP SoapClient 无法处理消息,因为内容类型为 'text/xml;
【发布时间】:2017-07-26 07:48:13
【问题描述】:

我无法连接到网络服务和发送/接收数据

错误

HTTP,无法处理消息,因为内容类型'text/xml; charset=utf-8' 不是预期的类型 'application/soap+xml; charset=utf-8'。

代码

$参数= [ '用户名' => 12324, '密码' => 432123, 'Bill_Id' => 153585611140, 'Payment_Id' => 8560103, ]; $url="https://bill.samanepay.com/CheckBill/BillStateService.svc?wsdl"; $method = "VerifyBillPaymentWithAddData"; $client = new SoapClient($url); 尝试{ $info = $client->__call($method, array($parameters)); }catch (SoapFault $fault){ die($fault->faultcode.','.$fault->faultstring); }

Notice : 不起作用 Soap 版本 1,1 和其他解决示例以解决 stackoverflow 中的此错误。

【问题讨论】:

    标签: php xml web-services soap soap-client


    【解决方案1】:

    你可以试试

    $url = "https://bill.samanepay.com/CheckBill/BillStateService.svc?wsdl";
    
    try {
        $client = new SoapClient($url, [
            "soap_version" => SOAP_1_2, // SOAP_1_1
            'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
            'trace' => 1,
            'exception' => 1,
            'keep_alive' => false,
            'connection_timeout' => 500000
        ]);
        print_r($client->__getFunctions());
    } catch (SOAPFault $f) {
        error_log('ERROR => '.$f);
    }
    

    验证您的方法名称是否正确。

    那里可以看到方法

    VerifyBillPaymentWithAddDataResponse VerifyBillPaymentWithAddData(VerifyBillPaymentWithAddData $parameters)
    

    接下来是检查类型VerifyBillPaymentWithAddData 以及参数是否可以是数组。 您也可以测试通过

    调用该方法
    $client->VerifyBillPaymentWithAddData([
        'UserName' => 12324,
        'Password' => 432123,
        'Bill_Id' => 153585611140,
        'Payment_Id' => 8560103,
    ]);
    

    或者你的,除了额外的数组

    $info = $client->__call($method, $parameters);
    

    编辑: 假设https://stackoverflow.com/a/5409465/1152471 错误可能在服务器端,因为服务器发回的标头与 SOAP 1.2 标准不兼容。

    也许您必须使用第三方库甚至简单的套接字才能使其正常工作。

    【讨论】:

      【解决方案2】:

      只需使用以下功能。玩得开心!

      function WebServices($function, $parameters){
              
          $username = '***';
          $password = '***';
      
          $url = "http://*.*.*.*/*/*/*WebService.svc?wsdl";
          $service_url = 'http://*.*.*.*/*/*/*WebService.svc';
          
      
          
          $client = new SoapClient($url, [
              "soap_version" => SOAP_1_2,
              "UserName"=>$username, 
              "Password"=>$password,
              "SOAPAction"=>"http://tempuri.org/I*WebService/$function",
              'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
              'trace' => 1,
              'exception' => 1,
              'keep_alive' => false,
              'connection_timeout' => 500000
          ]);
          $action = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', "http://tempuri.org/I*WebService/$function");
          $to = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'To', $service_url);
          $client->__setSoapHeaders([$action, $to]);
          try{
              return $client->__call($function, $parameters);  
          } catch(SoapFault $e){
              return $e->getMessage();
          }
      }
      

      【讨论】:

      • 为你的答案添加一些解释
      猜你喜欢
      • 2014-10-25
      • 2019-05-28
      • 2020-04-25
      • 2013-01-02
      • 2014-12-24
      • 1970-01-01
      • 2012-06-14
      • 2019-12-21
      • 1970-01-01
      相关资源
      最近更新 更多