SoapFaultexception:从PHP访问Java Web服务时不支持的媒体类型

我正在尝试使用Zend Framework v1.9.0中的Zend_Soap_Client连接到Java Web服务:

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

'; ?>

输出:

 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 

知道什么可能是错的吗? url是正确的,因为我在通话时获得了可用的function

 $client->getFunctions() 

根据此列表 ,该exception表示托管Web服务的服务器对您的请求编码不满意:

表示对等HTTP服务器不支持用于对请求消息进行编码的Content-type。 消息交换被视为已完成失败。

因此,您应该向Web服务提供商咨询他们期望的内容类型/编码。

如果您使用SOAP_1_2可能的解决方案是更改为SOAP_1_1因为这将改变所做的请求。

我没有使用Zend框架,但在JavaScript中有类似的XMLHttpRequest问题。 解决方案是在SOAP请求标头中指定Content-Type。

 var sr = ' 32'; 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);