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