【问题标题】:Apache Camel HTTP / HTTP4 ignores Content-Type headerApache Camel HTTP / HTTP4 忽略 Content-Type 标头
【发布时间】:2015-04-01 14:43:48
【问题描述】:

我正在尝试使用 camel-http 通过 Apache Camel 发送 http 调用。

当我设置标头 Content-Type 时,它​​会忽略标头并且不将其包含在调用中。

我已经尝试设置标题如下:

exchange.getOut().setHeader('Content-Type', 'application/json'),

和

exchange.getOut().setHeader(Exchange.CONTENT_TYPE, 'application/json');

我也尝试过使用 camel-http 和 camel-http4,但它们都不适用。

由于我必须强制发送 Content-Type 标头,我如何强制 Camel-HTTP 包含它?


注意:我还将其他标头设置为与调用正确发送的相同方式,只是 Content-Type 不起作用

【问题讨论】:

  • 你看过这个讨论吗? camel.465427.n5.nabble.com/…
  • 作为一种解决方法,将正文设置为空 json 文档 {},camel-http 自动检测内容类型为 application/json 并设置正确的 Content-Type 标头。

标签: json http-headers apache-camel


【解决方案1】:

您需要执行以下操作来设置 Content-Type:

<setHeader headerName="Content-Type">

        <constant>application/json</constant>

</setHeader>

这将用于设置 Content-Type。

【讨论】:

  • 这正是我正在做的,但如果 body 是空的 camel-http/camel-http4 会自动删除 Content-Type 标头。
  • 设置 Content-Type 标头后必须设置正文。像下面这样:&lt;setBody&gt; &lt;constant&gt;{ json text for body here }&lt;/constant&gt; &lt;/setBody&gt;
猜你喜欢
  • 1970-01-01
  • 2020-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-22
  • 2014-10-31
  • 1970-01-01
相关资源
最近更新 更多