NuSOAP:如何更改请求的内容类型?
使用 .NET WCF Web 服务时,我收到以下响应(错误):
不支持的 HTTP 响应状态 415 无法处理消息,因为内容类型为“text/xml;” 字符集=UTF-8' 不是预期的类型“application/soap+xml;” 字符集=utf-8'。
如何更改内容类型? 我在 NuSOAP 论坛/文档中找不到它,或者我可能忽略了一些东西......
When consuming a .NET WCF webservice I get the following response (error):
Unsupported HTTP response status 415
Cannot process the message because the content type 'text/xml; charset=UTF-8'
was not the expected type 'application/soap+xml; charset=utf-8'.
How do I change the content type? I can't find it in the NuSOAP forums/docs, or I might be overlooking something....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这对我有用:
$client = new nusoap_client($params);
$client->soap_defencoding = 'UTF-8';
勾选为正确的答案不适用于 NUSOAP,因此不是适当的答案。
This worked for me:
$client = new nusoap_client($params);
$client->soap_defencoding = 'UTF-8';
The answer that is ticked as correct is not for NUSOAP therefore not the appropriate answer.
我知道这是一篇旧帖子,但我跑到此页面寻找答案。
application/soap+xml
是使用 SOAP 1.2 时传递的内容类型,text/xml
与 SOAP 1.1 一起使用,类似这样的东西应该可以解决问题,
i know this is an old post, but i ran in to this page looking for an answer.
application/soap+xml
is the content-type passed when using SOAP 1.2,text/xml
is used with SOAP 1.1,something like this should do the trick,
您可以使用 Web 服务指定 NuSOAP 流的编码,如下所示:
You can specify the encoding of NuSOAP streams with the webservices like that :
看起来 NuSOAP 库中有一个轻微的遗漏...它假设内容标头必须是“text/xml”,因此如果您的客户端尝试连接到输出 application/soap+xml 标头的服务,那么您'最终会出现如下错误:
为了测试这一点,您可能会受益于以下小函数模式,我用它来登录 SOAP 服务。 请记住,打印出客户端对象! 您实际上可能看不到结果!
当我打印 $result 时,我什么也没得到,但是当我打印 $client 对象时,我可以看到有错误。
我实现的小技巧是在 nusoap.php 文件中,大约第 7500 行。查找这个 if 语句:
并将其更改为:
所做的就是让 NuSOAP 处理发出“application/soap+xml”标头的响应(这是一个有效的 xml 标头)。
It looks like there's a slight omission in the NuSOAP library... it assumes that the content headers MUST be "text/xml", so if your client is attempting to connect to a service that outputs application/soap+xml headers, you'll end up with errors like:
To test this, you may benefit from the following little function pattern, which I used to login to a SOAP service. Remember, print out the client object! You may not actually get a result to look at!
When I printed my $result, I got nothing, but when I printed out the $client object, I could see that there were errors.
The little hack I implemented was in the nusoap.php file, around line 7500. Look for this if-statement:
And change it to this:
All this does is it lets NuSOAP handle responses that issue an "application/soap+xml" header (which is a valid xml header).
我也被困在这个问题上。
秘密就在 web.config 中
将 wsHttpBinding 更改为 basicHttpBinding
像这样:
希望有帮助!
/埃里克
I was stuck on this as well.
The secret is in the web.config
Change wsHttpBinding to basicHttpBinding
Like so:
Hope that helps!
/Erik