SoapFault exception: [HTTP] Unsupported Media Type

2019-02-17 03:57发布

I'm trying to connect to a Java web-service using the Zend_Soap_Client from the Zend Framework v1.9.0:

<?php
include( 'Zend/Loader/Autoloader.php');
$autoloader = Zend_Loader_Autoloader::getInstance();
$client = new Zend_Soap_Client('https://webservice.com/webservice-war/webservice?wsdl'
    , array('encoding'=> 'UTF-8'));

try{
    $result = $client->find_customer(array('username' => 'user', 
                         'password' => '123'), array('city' => 'some city'));
} catch(Exception $e){
    echo $e;
}

echo '<pre>' . $client->getLastRequestHeaders() . '</pre>'; 
?>

Outputs:

SoapFault exception: [HTTP] Unsupported Media Type in 
/Library/ZendFramework-1.9.0/library/Zend/Soap/Client.php:937 
Stack trace: 
 #0 [internal function]:
SoapClient->__doRequest('_doRequest(Object(Zend_Soap_Client_Common),
    '__doRequest('__soapCall('find_customer', Array, NULL, NULL, Array) 
 #6 [internal function]:  
 Zend_Soap_Client->__call('find_customer', Array) 
 #7 /Users/webservicetest/index.php(8): 
 Zend_Soap_Client->find_customer(Array, Array) 
 #8 {main}

POST /webservice-war/webservice HTTP/1.1
Host: webservice.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.2.6
Content-Type: application/soap+xml; charset=utf-8; action=""
Content-Length: 315

Any idea what could be wrong? The url is correct, since I get the availible functions when calling

$client->getFunctions()

2条回答
男人必须洒脱
2楼-- · 2019-02-17 04:31

According to this listing, the exception indicates that the server hosting the web-service is not happy with your requests encoding:

Indicates that the peer HTTP server does not support the Content-type used to encode the request message. The message exchange is regarded as having completed unsuccessfully.

So you should check with the web-service provider concerning the content-type/encoding they expect.

A possible solution if you are using SOAP_1_2is to change to SOAP_1_1 since that will alter the requests made.

查看更多
可以哭但决不认输i
3楼-- · 2019-02-17 04:37

I am not using Zend framework, but had a similar problem with XMLHttpRequest in JavaScript. The solution was to specify the Content-Type in the SOAP request header.

var sr = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.w3schools.com/webservices/">  <SOAP-ENV:Body><ns1:CelsiusToFahrenheit><ns1:Celsius>32</ns1:Celsius></ns1:CelsiusToFahrenheit></SOAP-ENV:Body></SOAP-ENV:Envelope>';
http_request = new XMLHttpRequest();
http_request.open('POST', 'http://www.w3schools.com/webservices/tempconvert.asmx', true);
http_request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
http_request.send(sr);
查看更多
登录 后发表回答