使用 .NET WCF Web 服务时,我收到以下响应(错误):
不支持的 HTTP 响应状态 415 无法处理消息,因为内容类型为 'text/xml; charset=UTF-8' 不是预期的类型 'application/soap+xml; 字符集=utf-8'。
如何更改内容类型?我在 NuSOAP 论坛/文档中找不到它,或者我可能忽略了某些东西....
使用 .NET WCF Web 服务时,我收到以下响应(错误):
不支持的 HTTP 响应状态 415 无法处理消息,因为内容类型为 'text/xml; charset=UTF-8' 不是预期的类型 'application/soap+xml; 字符集=utf-8'。
如何更改内容类型?我在 NuSOAP 论坛/文档中找不到它,或者我可能忽略了某些东西....
我知道这是一个旧帖子,但我跑到这个页面寻找答案。
application/soap+xml
是使用 SOAP 1.2 时传递的内容类型,
text/xml
与 SOAP 1.1 一起使用,
像这样的东西应该可以解决问题,
$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_1));
您可以使用以下 Web 服务指定 NuSOAP 流的编码:
$client = new nusoap_client($params);
$client->soap_defencoding = 'UTF-8';
看起来 NuSOAP 库中略有遗漏......它假定内容标头必须是“text/xml”,因此如果您的客户端尝试连接到输出应用程序/soap+xml 标头的服务,您'最终会出现以下错误:
响应不是 text/xml 类型:application/soap+xml;字符集=utf-8
为了测试这一点,您可能会受益于以下我用来登录 SOAP 服务的小函数模式。请记住,打印出客户端对象!您实际上可能看不到结果!
require_once('path/to/downloaded/libraries/nusoap.php');
var $endpoint = 'https://somedomain.com/path/to/soap/server/Login';
var $client; // the soapclient object
function SOAP_Login()
{
$this->client = new soapclient($this->endpoint);
$err = $this->client->getError();
if ($err)
{
// Display the error
echo '<p><b>SOAP Constructor error: ' . $err . '</b></p>';
exit;
// At this point, you know the call that follows will fail
}
$params = array(
'some' => 'thing.. depends on what the WSDL expects'
);
$result = $this->client->call('someFunction', $params);
print_r($result); // Without the fix, this prints nothing (i.e. false) !!!
print_r($this->client); // Instead, look at the state of the client object, specifically error_str and debug_str
}
当我打印我的 $result 时,我什么也没得到,但是当我打印出 $client 对象时,我可以看到有错误。
我实现的小技巧在 nusoap.php 文件中,大约第 7500 行。查找以下 if 语句:
if (!strstr($headers['content-type'], 'text/xml')) {
$this->setError('Response not of type text/xml: ' . $headers['content-type']);
return false;
}
并将其更改为:
if (!strstr($headers['content-type'], 'text/xml') && !strstr($headers['content-type'], 'application/soap+xml') ) {
$this->setError('Response not of type text/xml: ' . $headers['content-type']);
return false;
}
这一切只是让 NuSOAP 处理发出“application/soap+xml”标头(这是一个有效的 xml 标头)的响应。
我也被困在这个问题上。
秘诀是在 web.config 中将 wsHttpBinding 改为 basicHttpBinding
像这样:
<endpoint address="" binding="basicHttpBinding" contract="YourProject.View.Whatever.IYourService">
希望有帮助!/埃里克
这对我有用:
$client = new nusoap_client($params);
$client->soap_defencoding = 'UTF-8';
勾选正确的答案不适用于 NUSOAP,因此不是适当的答案。