问题
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