路線:駱駝http4組件411壞的Content-Length
from("direct:start")
.setProperty(Exchange.CHARSET_NAME, constant("iso-8859-1"))
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Message m = exchange.getOut();
m.setBody(exchange.getIn().getBody());
m.setHeader(Exchange.HTTP_METHOD, HttpMethods.POST);
m.setHeader(Exchange.CONTENT_ENCODING, "gzip");
m.setHeader(Exchange.CONTENT_LENGTH, m.getBody(byte[].class).length);
m.setHeader(HttpHeaders.CONTENT_TYPE, "application/xml");
m.setHeader(Exchange.HTTP_CHARACTER_ENCODING, "iso-8859-1");
m.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip, deflate");
}
})
.marshal().gzip()
.to("http4://remote.com/path")
.unmarshal().gzip();
什麼我送:
String body = "<?xmlversion=\"1.0\"encoding=\"ISO-8859-1\"?><theXml></theXml>";
producer.sendBody(body);
我越來越
HTTP操作失敗,調用http://remote.com/path用的StatusCode: 411
這條路線有什麼遺漏/錯誤?
編輯
正確的路線會
from("direct:start")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Message m = exchange.getOut();
m.setBody(exchange.getIn().getBody());
m.setHeader(Exchange.HTTP_METHOD, HttpMethods.POST);
m.setHeader(Exchange.CONTENT_ENCODING, "gzip");
m.setHeader(Exchange.CONTENT_TYPE, "application/xml");
}
})
// http4 takes care of compressing/decompressing gzip
.to("http4://remote.com/path")
但現在我有一個問題:在遠程服務器不處理「傳輸編碼:Chuncked」,這似乎是默認方式camel-http4做到了。 而我不知道如何關閉Chunked。
參見下一個問題How to turn off 「Transfer-Encoding Chuncked」 in Camel-http4?
嗯。 HTTP狀態代碼非常清晰 - 服務器期待Content-Length標題......但您明確地在請求中設置了一個。 – Charles