搜索

150.2. 例子

download PDF

使用 POST 使用正文调用 url,并返回响应作为 out 消息。如果正文为 null 调用 URL,使用 GET 并返回响应作为 out 信息

Java DSL

Spring DSL

from("direct:start")
  .to("http://myhost/mypath");
<from uri="direct:start"/>
<to uri="http://oldhost"/>

您可以通过添加一个标头来覆盖 HTTP 端点 URI。Camel 将调用 http://newhost。例如 REST urls 是非常方便的。

Java DSL

from("direct:start")
  .setHeader(Exchange.HTTP_URI, simple("http://myserver/orders/${header.orderId}"))
  .to("http://dummyhost");

URI 参数可以直接在端点 URI 或标头上设置

Java DSL

from("direct:start")
  .to("http://oldhost?order=123&detail=short");
from("direct:start")
  .setHeader(Exchange.HTTP_QUERY, constant("order=123&detail=short"))
  .to("http://oldhost");

将 HTTP 请求方法设置为 POST

Java DSL

Spring DSL

from("direct:start")
  .setHeader(Exchange.HTTP_METHOD, constant("POST"))
  .to("http://www.google.com");
<from uri="direct:start"/>
<setHeader headerName="CamelHttpMethod">
  <constant>POST</constant>
</setHeader>
<to uri="http://www.google.com"/>
<to uri="mock:results"/>
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.