40.15. 如何将 http 方法(GET/PATCH/POST/PUT/DELETE/HEAD/OPTIONS/TRACE)设置为 HTTP producer
HTTP 组件提供了一种通过设置消息标头来设置 HTTP 请求方法的方法。下面是一个示例:
from("direct:start")
.setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http.HttpMethods.POST))
.to("http://www.google.com")
.to("mock:results");
可以使用字符串常量编写时间较短:
.setHeader("CamelHttpMethod", constant("POST"))
以及等同的 Spring 示例:
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="direct:start"/>
<setHeader name="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<to uri="http://www.google.com"/>
<to uri="mock:results"/>
</route>
</camelContext>