java 如何避免“505:不支持 HTTP 版本”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3435119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:50:58  来源:igfitidea点击:

How to avoid "505: HTTP Version not supported" error?

javaweb-servicesjax-wsbing-apihttp-status-code-505

提问by moxn

I am trying to use the Bing SOAP API for a simple search request. But now that I finally figured out how to send the request using JAX-WS, I am stuck again. I get the reply com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 505: HTTP Version not supportedwhen I send the request. Can anyone help me out?

我正在尝试将 Bing SOAP API 用于简单的搜索请求。但是现在我终于弄清楚了如何使用 JAX-WS 发送请求,我又被卡住了。com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 505: HTTP Version not supported当我发送请求时,我得到了答复 。谁能帮我吗?

I am using dynamic invocation with JAX-WS 2.0, if that makes any difference.

我正在使用 JAX-WS 2.0 的动态调用,如果这有什么不同的话。

Dispatch<SOAPMessage> dispatch = service.createDispatch(
    portName, SOAPMessage.class, Service.Mode.MESSAGE);
MessageFactory messageFactory = ((SOAPBinding) dispatch.getBinding())
    .getMessageFactory();
SOAPMessage request = messageFactory.createMessage();
// Add content to the request
SOAPMessage response = dispatch.invoke(request);

Wireshark tells me, that the request header contains POST /soap.asmx HTTP/1.1and the reply comes back also with an HTTP/1.1 versioning. Doesn't this mean, it's alright?

Wireshark 告诉我,请求标头包含POST /soap.asmx HTTP/1.1并且回复也带有 HTTP/1.1 版本。这不是说,没关系吗?

Thanks, moxn

谢谢,莫克斯

UPDATE: It's not a JAX-WS specific error. I implemented the communication via Commons HTTPClient and still get the same 505.

更新:这不是 JAX-WS 特定的错误。我通过 Commons HTTPClient 实现了通信,但仍然得到相同的 505。

Following the headers from the HTTPClient request:

遵循 HTTPClient 请求的标头:

Content-Length: 435
Content-Type: text/xml
Host: api.bing.net:80
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.0.1 (java 1.5)
Expect: 100-Continue

UPDATE: It also doesn't work with HTTP/1.0 btw...

更新:它也不适用于 HTTP/1.0 顺便说一句...

采纳答案by moxn

In the meantime I got my answer in the Bing developer forum. It seems as if Microsoft is sort of using different semantics for HTTP response codes than most and a 505 can also mean "Something is wrong with your SOAP request". Turns out I did not use the correct namespaces. After fixing them, the request went through just fine.

与此同时,我在 Bing 开发者论坛上得到了答案。似乎微软对 H​​TTP 响应代码使用了与大多数不同的语义,505 也可能意味着“你的 SOAP 请求有问题”。原来我没有使用正确的命名空间。修复它们后,请求通过得很好。

Here is the link to the threadin the Bing forum.

这是Bing 论坛中该主题链接

回答by Chris Voon

Have you tried adding the following to app.config or web.config?

您是否尝试将以下内容添加到 app.config 或 web.config?

<configuration>
  <system.net>
    <settings>
      <servicePointManager expect100Continue="false" />
    </settings>
  </system.net>
</configuration>

Obviously sending the Expect: 100-continuein request header causes the “505: HTTP Version not supported” error to be thrown.

显然,发送Expect: 100-continuein 请求头会导致抛出“505: HTTP Version not supported”错误。

Expect 100-continue

期待 100-继续