[英]How do I set the Content-Type on a camel-restlet producer request?
我需要使用简单的Rest服务,但是如果我的请求以Content-type:application / x-www-form-urlencoded结束,它们的实现就会中断。 我需要将其设置为“application / json”或面对状态415。
我正在使用restlet生成器组件,因为它已经在整个过程中使用,到目前为止它已经在功能和简单性之间达到了最佳点。 至今。
无论如何,尝试在我的路线中设置标题似乎没有效果,我的请求的内容类型仍然是application / x-www-form-urlencoded。 这是我的测试代码:
from("direct:getImg")
.setHeader(RestletConstants.RESTLET_LOGIN, simple("admin"))
.setHeader(RestletConstants.RESTLET_PASSWORD, simple("admin"))
.setHeader(Exchange.CONTENT_TYPE, simple("application/json"))
.to("restlet:http://requestb.in/12sowlx1?restletMethod=get&throwExceptionOnFailure=false")
我显然错过了什么,但我找不到任何例子。 任何人都可以指出正确的方法吗?
谢谢!
您应该在调用restlet之前调用处理器并在交换中设置内容类型。 像这样的东西:
from("direct:getImg").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.CONTENT_TYPE, MediaType.APPLICATION_XML);
}
}).to("restlet:http://requestb.in/12sowlx1?restletMethod=get&throwExceptionOnFailure=false");
我测试了它,它的工作原理。 让我知道结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.