URLConnection writing different request headers
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Andrew_Cartine
Posted On:   Friday, June 29, 2001 08:00 AM

Ever have a situation where using the same exact URLConnection code actually results in two different request headers? Check this out: POST / HTTP/1.1 Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Accept-Language: en-us Accept-Encoding: gzip, deflate User-Agent: Java1.3.0_01 Host: 10.0.0.4 Content-length: 25 Content-Type: application/x-www-form-urlencoded Content-Length: 25 versus... POST / HTTP/1.1 User-Agent: Java1.3.0_02 Host: 10.0.0.4 Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive Content-type: application/x-www-form-urlencoded    More>>

Ever have a situation where using the same exact URLConnection code actually results in two different request headers? Check this out:


			
POST / HTTP/1.1
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Java1.3.0_01
Host: 10.0.0.4
Content-length: 25
Content-Type: application/x-www-form-urlencoded
Content-Length: 25




versus...



			
POST / HTTP/1.1
User-Agent: Java1.3.0_02
Host: 10.0.0.4
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-type: application/x-www-form-urlencoded
Content-length: 25


What's *that* all about? Here is the code used in both situations:


			
URL url = new URL( "http://10.0.0.4" );
URLConnection conn = url.openConnection();
conn.setDoOutput( true );
conn.setDoInput( true );
OutputStream out = conn.getOutputStream();
out.write( postQuery.getBytes() );
out.flush();
conn.getInputStream();
   <<Less

Re: URLConnection writing different request headers

Posted By:   Tim_Rohaly  
Posted On:   Friday, June 29, 2001 12:45 PM

The difference comes from fact that you are using
two different versions of Java - the first one uses
Java 1.3.0_01 and the second uses Java 1.3.1_02.
(I can tell this by the "User-Agent" header).


It is certainly well within the bounds of expected
behavior that different versions of Java use different
headers, since the headers reflect in part the capabilities
of the URLConnection implementation.

About | Sitemap | Contact