使用状态码 405 获取 org.apache.camel.component.http.HttpOperationFailedException

Posted

技术标签:

【中文标题】使用状态码 405 获取 org.apache.camel.component.http.HttpOperationFailedException【英文标题】:Getting org.apache.camel.component.http.HttpOperationFailedException with Status Code 405 【发布时间】:2012-04-03 03:41:31 【问题描述】:

我正在运行 servicemix 4.4.1。我正在尝试使用 camel-http4 对网站进行 http 调用。无论我尝试调用哪个网站,我都会收到此错误: org.apache.camel.RuntimeCamelException:org.apache.camel.component.http.HttpOperationFailedException:HTTP 操作调用http://servicemix.apache.org/downloads/servicemix-4.4.0.html 失败,状态码:405

这是我的代码 sn-p:

 <camelContext xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="activemq://events1"/>
<setHeader headerName="CamelHttpMethod">
    <constant>POST</constant>
</setHeader>
    <to uri="http://servicemix.apache.org/downloads/servicemix-4.4.0.html"/>
    <to uri="log:events"/>
  </route>
</camelContext>

我尝试了许多网站并尝试使用不同的 http 方法(post 与 get),但我不断收到相同的错误。任何想法?提前致谢。

【问题讨论】:

【参考方案1】:

您指定的网站不是表单的目标。所以很可能它只允许 GET 请求而不是 POST。所以尝试将 CamelHttpMethod 设置为 GET。

顺便说一句。你想用你的路线实现什么?如果您想将 activeMQ 消息发送到网站,则 POST 可以,但您必须使用接受 POST 的网站。

您可以通过定义自己的路由来接收请求来实现这一点。

然后您可以在第一条路由中发送到该网址。

【讨论】:

感谢您的帮助。奇怪的是,我认为通过不定义 CamelHttpMethod,http 方法会被假定为 GET。我尝试将方法显式设置为 GET 而不是 POST,这似乎奏效了。再次感谢您对此的帮助。 Camel 通过查看 url 来猜测使用哪种 http 方法。所以它并不总是默认使用get。请参阅“使用 GET 或 POST 调用”部分中的camel.apache.org/http.html,其中描述了算法。【参考方案2】:

我检查了这个; 通过设置选项“bridgeEndpoint”解决的问题; 您将 http 端点设置为 bridgeEndpoint,这意味着请求 url 将使用请求 URI 进行更新。

<route>
   <from uri="-------"/>
   <to uri="jetty://http://localhost:9090/my.html?bridgeEndpoint=true"/
   <to uri="log:events"/>
</route>

【讨论】:

这正是我的问题。感谢您的回答 (+1)。

以上是关于使用状态码 405 获取 org.apache.camel.component.http.HttpOperationFailedException的主要内容,如果未能解决你的问题,请参考以下文章

使用scrapy访问网页返回405状态码错误

nginx错误码405是啥状态

状态码 405、PUT 和 DELETE 操作方法是不允许的

flask axios post返回http状态码405/400

http 请求 返回状态码 405 的问题

ASP.NET Web API、405 状态码和异常处理