SoapFault异常:[HTTP]从PHP访问Java web服务时不支持的媒体类型
我正在尝试使用Zend Framework v1.9.0中的SoapFault异常:[HTTP]从PHP访问Java web服务时不支持的媒体类型,java,php,zend-framework,soap,web-services,Java,Php,Zend Framework,Soap,Web Services,我正在尝试使用Zend Framework v1.9.0中的Zend_Soap_客户端连接到Java web服务: <?php include( 'Zend/Loader/Autoloader.php'); $autoloader = Zend_Loader_Autoloader::getInstance(); $client = new Zend_Soap_Client('https://webservice.com/webservice-war/webservice?wsdl'
Zend_Soap_客户端
连接到Java web服务:
<?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>';
?>
你知道会出什么问题吗?url是正确的,因为我在调用
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);
根据,异常表示承载web服务的服务器对您的请求编码不满意:
指示对等HTTP服务器
不支持使用的内容类型
对请求消息进行编码。这个
消息交换被视为具有
没有成功地完成
因此,您应该向web服务提供商询问他们期望的内容类型/编码
如果您使用的是
SOAP\u 1\u 2
,一个可能的解决方案是更改为SOAP\u 1\u 1
,因为这将改变所做的请求。我没有使用Zend framework,但JavaScript中的XMLHttpRequest也有类似的问题。解决方案是在SOAP请求头中指定内容类型
var sr='32';
http_请求=新的XMLHttpRequest();
http_请求.open('POST','http://www.w3schools.com/webservices/tempconvert.asmx",对),;
setRequestHeader(“内容类型”,“text/xml;charset=utf-8”);
http_请求发送(sr);
更具体一些:。通过在选项中设置'soap_version'=>soap_1_1,使请求通过text/xml而不是application/soap传递来解决+xml@MadsMobæk Brilliant解决了我遇到的一个相同问题;对于soap 1.1,字符集=utf-8,内容类型:application/soap+xml;对于soap 1.2,字符集=utf-8
$client->getFunctions()
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);