473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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:

Expand|Select|Wrap|Line Numbers
  1. Calendar calendar = Calendar.getInstance();
  2.         java.util.Date now = calendar.getTime();
  3.         java.sql.Timestamp currentTimestamp = new java.sql.Timestamp(now.getTime());
  4.         System.out.println(currentTimestamp.getTime());
  5.  
  6.  
  7. InputStream is2=null;
  8. OutputStream os2=null;
  9. String request="";
  10.         try {
  11.             Socket pierce2 = new Socket("service.atty-pierce.com", 80);
  12.             os2=pierce2.getOutputStream();
  13.             is2=pierce2.getInputStream();
  14.             request+="GET /WFLogon?inv=cl457239&turnCacheOff=" + Long.toString(currentTimestamp.getTime()) + " HTTP/1.1\r\n";
  15.             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";
  16.             request+="Referer: http://service.atty-pierce.com/\r\n";
  17.             request+="Accept-Language: en-us\r\n";
  18.             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";
  19.             request+="Accept-Encoding: gzip, deflate\r\n";
  20.             request+="Host: service.atty-pierce.com\r\n";
  21.             request+="Proxy-Connection: Keep-Alive\r\n\r\n";
  22.             System.out.print(request);
  23.             os2.write(request.getBytes());
  24.  
  25.             int c;
  26.             do
  27.             {
  28.                 char x;
  29.                 c=is2.read();
  30.                 x=(char)c;
  31.                 if (c!=-1) System.out.print(x);
  32.             } while (c!=-1);
  33.  
  34.         } catch (Exception ex) {
  35.             Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  36.         }
  37.  
Sep 25 '10 #1
0 1637

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Roger Twomey | last post by:
I have an application that checks for browser, version and active X enabled. It uses the result for a simple if then. The issue I have is that Request.Browser.MajorVersion is returning the...
3
by: Ganesh | last post by:
I am a .NET Professional and working in web development. I found a bug (i think so) while using Request.Browser object to identify the browser name and version. It shows me the correct browser name...
1
by: ocn0248 | last post by:
The code bellow must be executed under safari web-browser. I need to know how I can get the major version of the safari web-browser. Thanks in advance vb.net code Partial Class SafariTest...
5
by: whoopding | last post by:
How can I return all the properties in the Request.Browser object using a for each...next loop?
3
by: Bill | last post by:
Has anyone used/tested Request.Browser.Crawler ? Is it reliable, or are there false positives/negatives? Thanks!
4
by: customerservice | last post by:
I have been tracking website traffic on my site www.grabbagvideo.com:84 and also https://www.grabbagvideo.com for a few weeks now. I am using the request.browser.crawler property in attempt to...
1
by: Alex D. | last post by:
does anybody knos the string for the Opera browser to do something similar to : this.Request.Browser.IsBrowser("IE"). Thanks, Alex.
2
by: clintonG | last post by:
Does the documented property value UNIX mean the Request.Browser.Platform property determines requests are being made from a Linux machine? <%= Clinton Gallagher NET csgallagher AT...
0
by: germ | last post by:
we are running into a situation where accessing Request.Browser.MajorVersion causes a System.ArgumentNullException. when this happens the HTTP_USER_AGENT value is "Mozilla/4.x (Win95)" I am...
1
by: Nathan Sokalski | last post by:
Where can I find out what values are submitted by different browsers for Page.Request.Browser.Browser? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.