1

使用 Apache Camel-Http 组件未填充为 GET 方法设置 Content-Type。

exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json");

而使用 POST 方法时也是如此。

了解没有方法 GET 的主体。奇怪的是,如果 body 设置为空 string("") Content-Type 正在传递,但方法类型也更改为 POST。

exchange.getIn().setBody("");

2.13.1 是我目前使用的 Camel 版本。也试过最新版本,还是一样。有什么我想念的吗。

服务要求传递 Content-Type。

4

1 回答 1

0

在 Camel 源代码中有一个针对这种场景的测试:https ://github.com/apache/camel/blob/master/components/camel-http4/src/test/java/org/apache/camel/component/ http4/HttpProducerContentTypeTest.java

在这两个测试用例中,都需要设置主体。您应该在 camel-http4 中看到这一点:

https://github.com/apache/camel/blob/master/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java#L482-L582

还有骆驼http:

https://github.com/apache/camel/blob/master/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java#L447-L506

如果您决定使用 Http4/http 组件,那么您需要设置一个正文。

还有一个关于 nabble 的非常古老的讨论:http://camel.465427.n5.nabble.com/Http4-Set-Header-Content-Type-not-passing-through-to-the-HTTP-Request-td5746414 。 html

于 2017-11-07T12:56:18.670 回答