简体   繁体   English

PHP SoapClient 无法处理消息,因为内容类型为 'text/xml;

[英]PHP SoapClient Cannot process the message because the content type 'text/xml;

I cannot connect to webservice and send/receive data我无法连接到网络服务并发送/接收数据

Error错误

HTTP,Cannot process the message because the content type 'text/xml; HTTP, 无法处理消息,因为内容类型为 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8' 不是预期的类型 'application/soap+xml; charset=utf-8'.字符集=utf-8'。

Code代码

$parameters = [
        'UserName' => 12324,
        'Password' => 432123,
        'Bill_Id' => 153585611140,
        'Payment_Id' => 8560103,
    ];

    $url="https://bill.samanepay.com/CheckBill/BillStateService.svc?wsdl";
    $method = "VerifyBillPaymentWithAddData";

    $client = new SoapClient($url);

    try{

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

    }catch (SoapFault $fault){  

        die($fault->faultcode.','.$fault->faultstring);

    }

Notice : not work Soap version 1,1 and other resolve sample for this error in stackoverflow. Notice :在 stackoverflow 中,此错误的 Soap 版本 1,1 和其他解决示例不起作用。

You could try你可以试试

$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);
}

to verify that your method name is correct.验证您的方法名称是否正确。

There you can see the method在那里你可以看到方法

VerifyBillPaymentWithAddDataResponse VerifyBillPaymentWithAddData(VerifyBillPaymentWithAddData $parameters)

Next is to check the Type VerifyBillPaymentWithAddData and if the parameter can be an array.接下来是检查 Type VerifyBillPaymentWithAddData以及参数是否可以是数组。 Also you could test to call the method via您也可以测试通过调用该方法

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

or yours except the additional array或者你的,除了额外的数组

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

EDIT: Assuming to https://stackoverflow.com/a/5409465/1152471 the error could be on the server side, because the server sends an header back that is not compatible with SOAP 1.2 standard.编辑:假设到https://stackoverflow.com/a/5409465/1152471 ,错误可能在服务器端,因为服务器发送回与 SOAP 1.2 标准不兼容的标头。

Maybe you have to use an third party library or even simple sockets to get it working.也许您必须使用第三方库甚至是简单的套接字才能使其正常工作。

Just use the following function.只需使用以下功能。 Have fun!玩得开心!

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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM