我有一个producer template来调用Http4 end point。如何获取http状态响应代码(如200,201等)?
Map<String, Object> headers = new HashMap<>();
headers.put(Exchange.HTTP_METHOD, GET);
producerTemplate.requestBodyAndHeaders("https4://myhostname.com:443/myURL", null, headers, String.class);
答案 0 :(得分:4)
尝试这样的事情(Camel docu的轻微排列):
Exchange exchange = template.send("https4://myhostname.com:443/myURL", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_METHOD, GET);
}
});
Message out = exchange.getOut();
int responseCode = out.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
它可能也可以在不通过处理器的情况下工作,因为如果正文为空,http4默认为GET。
答案 1 :(得分:1)
请参阅此documentation:
它位于标题Exchange.HTTP_RESPONSE_CODE