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

♀尐吖头ヾ 提交于 2019-12-13 08:57:14

问题


I cannot connect to webservice and send/receive data

Error

HTTP,Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=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.


回答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. 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.

Maybe you have to use an third party library or even simple sockets to get it working.



来源:https://stackoverflow.com/questions/45320590/php-soapclient-cannot-process-the-message-because-the-content-type-text-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!