• Post Reply Bookmark Topic Watch Topic
  • New Topic

Identical request in browser and Java with different responses, why does this happen?  RSS feed

 
John Kay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a java program that is sending a HTTP 1.1 request and getting a response from a web server. The request that I am sending is identical to the one in the browser, IE8. I am using ieHTTPheaders to see what the headers are for the request. I am mimicking this request exactly in java(except for the cookie and the time stamp which is the number after "turnCacheOff="), but in my response headers I get in java specifically the header Transfer-Encoding: chunked is different than the header Content-Length: 1327 that I get in the browser. Why does this happen when the requests are exactly the same? Here is the browser request headers:

GET /WFLogon?inv=cl457239&turnCacheOff=1285437824858 HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: http://service.atty-pierce.com/
Accept-Language: en-us
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB6; Comcast Install 1.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.2; .NET CLR 3.5.30729)
Accept-Encoding: gzip, deflate
Host: service.atty-pierce.com
Proxy-Connection: Keep-Alive

Browser Response Headers:

HTTP/1.1 200 OK
Server: WebSphere Application Server/5.0
Set-Cookie: JSESSIONID=0000aZd4utW600Wzgi11Rg8qywu:-1;Path=/
Cache-Control: no-cache="set-cookie,set-cookie2"
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Content-Type: text/html; charset=UTF-8
Content-Language: en-US
Content-Length: 1327

In my java program the request headers are identical the that of the browser but the response comes back as:

HTTP/1.1 200 OK
Server: WebSphere Application Server/5.0
Set-Cookie: JSESSIONID=0000__qTreRMAs-768fpanccifr:-1;Path=/
Cache-Control: no-cache="set-cookie,set-cookie2"
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Content-Type: text/html; charset=UTF-8
Content-Language: en-US
Transfer-Encoding: chunked

Here is the code that I am using to make the request:


# Calendar calendar = Calendar.getInstance();
# java.util.Date now = calendar.getTime();
# java.sql.Timestamp currentTimestamp = new java.sql.Timestamp(now.getTime());
# System.out.println(currentTimestamp.getTime());
#
#
# InputStream is2=null;
# OutputStream os2=null;
# String request="";
# try {
# Socket pierce2 = new Socket("service.atty-pierce.com", 80);
# os2=pierce2.getOutputStream();
# is2=pierce2.getInputStream();
# request+="GET /WFLogon?inv=cl457239&turnCacheOff=" + Long.toString(currentTimestamp.getTime()) + " HTTP/1.1\r\n";
# request+="Accept: image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n";
# request+="Referer: http://service.atty-pierce.com/\r\n";
# request+="Accept-Language: en-us\r\n";
# request+="User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB6; Comcast Install 1.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.2; .NET CLR 3.5.30729)\r\n";
# request+="Accept-Encoding: gzip, deflate\r\n";
# request+="Host: service.atty-pierce.com\r\n";
# request+="Proxy-Connection: Keep-Alive\r\n\r\n";
# System.out.print(request);
# os2.write(request.getBytes());
#
# int c;
# do
# {
# char x;
# c=is2.read();
# x=(char)c;
# if (c!=-1) System.out.print(x);
# } while (c!=-1);
#
# } catch (Exception ex) {
# Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
# }
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe response sent would be large... Since Content Length is not known for dynamically getting generated response, it will be divided into chunks of data and sent as chunks...
 
John Kay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why would it be different in the browser and different in the java application that I wrote. I would expect to get the same response for identical requests.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12090
246
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While there is nothing wrong with posting the same topic in another forum, it is requested that you be BeForthrightWhenCrossPostingToOtherSites
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12090
246
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this consistent behavior? That is, if you run the same request multiple times in IE, do you always get a specified transfer length? And if you run it multiple times through Java, do you always get a chunked response?

The reason I ask is that choosing whether to send as a chunked response is usually something that is up to the server - it can choose whether to wait until it has all the data, or it can start sending data back before the entire message has been marshaled.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12090
246
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also - what is the size of the total response you get through Java? Is it the same size as the response the IE request generates? Or is it greater than the size of the Write Buffer Size defined in the WebSphere server you are connecting to?
 
John Kay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to posting and wasn't aware the cross posting could be an issue. Sorry about that, I will make sure I make that I include that information next time. As for the responses they are consistent in both the browser and in the java program. The body content is identical after comparing the two. So I guess practically speaking that the java application is working properly, but I don't understand how could the server choose do chunk on the java application and not chunk in IE8 when the requests are identical. There must be something that is creating that effect. Can it have to do with how the underlying protocols are being dealt with in java? Like TCP or IP?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!