I’m using HttpClient 4.3.6 on Java 1.7.0_95. I’m finding that in certain
circumstances, HttpClient is adding a spurious blank line to the headers. This
is then causing the far end server to treat the remaining headers as the body -
not what is desired!
If I run the code as a stand alone Java app, it works a treat. But sometimes,
when run under Tomcat, I get this spurious blank line.
I’ve switched on full wire tracing and I’m seeing:
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "POST /signin HTTP/1.1[\r][\n]"
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "X-CREDENTIALS: *SNIP*[\r][\n]"
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "[\r][\n]"
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "Accept: application/xml[\r][\n]"
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "Content-Type: application/xml[\r][\n]"
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "Content-Length: 0[\r][\n]"
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "Host: www.example.com:443[\r][\n]"
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "Connection: Keep-Alive[\r][\n]"
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "User-Agent: Apache-HttpClient/4.3.6 (java 1.5)[\r][\n]"
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "Accept-Encoding: gzip,deflate[\r][\n]"
2016-03-17 16:59:39,991 [TP-Processor3] DEBUG http.wire gr306 - http-outgoing-1
>> "[\r][\n]"
I’ve added code to check the headers that I’m adding to the HTTPPost instance,
and I’m not adding any blank or spurious headers.
httpPost = new HttpPost(path);
for(String header: headers.keySet())
{
logger.trace("Adding Header to Request: " + header);
httpPost.addHeader(header, headers.get(header));
}
Shows:
2016-03-17 16:59:39,986 [TP-Processor3] TRACE util.BasicHttpClient gr306 -
Adding Header to Request: X-CREDENTIALS
2016-03-17 16:59:39,986 [TP-Processor3] TRACE util.BasicHttpClient gr306 -
Adding Header to Request: Accept
2016-03-17 16:59:39,986 [TP-Processor3] TRACE util.BasicHttpClient gr306 -
Adding Header to Request: Content-Type
As I said, when this same library code is run as a standalone Java app, the
blank header line disappears.
Any suggestions as to how I can track this down?
Thank you.
GTG
--
Gordon Ross,
UIS Telecoms Office,
University of Cambridge