【问题标题】:How to avoid "505: HTTP Version not supported" error?如何避免“505:不支持 HTTP 版本”错误?
【发布时间】:2010-08-08 16:35:57
【问题描述】:

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

我正在使用 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 告诉我,请求标头包含POST /soap.asmx HTTP/1.1,并且回复也带有 HTTP/1.1 版本。这不是说,没关系吗?

谢谢,莫克斯

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

遵循 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

更新: 它也不适用于 HTTP/1.0 btw...

【问题讨论】:

  • 您能否显示您尝试发送的完整请求(URL 和 Wireshark 捕获的完整帖子)?有时 URL 或帖子中的空格会导致此问题。即错误可能指向与您认为的不同的问题..
  • @gbvb 嘿,感谢您的询问。我完全忘记了这个问题。我已经弄清楚了(见下面的答案)。

标签: java web-services jax-ws bing-api http-status-code-505


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    与此同时,我在 Bing 开发者论坛上得到了答案。似乎微软在某种程度上对 HTTP 响应代码使用了与大多数人不同的语义,并且 505 也可能意味着 “您的 SOAP 请求有问题”。原来我没有使用正确的命名空间。修复它们后,请求就顺利通过了。

    这是必应论坛中的link to the thread

    【讨论】:

    • 很好地解决了这一问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    • 2011-02-14
    • 2019-03-10
    相关资源
    最近更新 更多