Queer Problem

G

Guest

C#, WinXP SP2, VS 2005Beta2

I need to emulate the browser functionality wihin my app. I need to visit a
web page , parse it and post back the results to another page. Everything
works fine, except that when the steps are performed from the browser, the
web server provides an extra set-cookie header in the second page's response.
Here is a trace:

From the browser:
POST /saregamapa/admin/srgma_vote_results.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*
Referer: http://sifymax.com/saregamapa/admin/srgma_vote_page.php
A ccept-Language: en-us
Content-Type: application/x-www-form-urlencoded
XXXXXXXXXXXXXXX:++++++++++++++
User-Agen t: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
CLR 1.0.3705; Media Center PC 2.8; .NET CLR 2.0.50727)
Host: sifymax.com
Content-Length: 60
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: Cookie_Enable=1

vote=274331d3c115b6a2011&vote_code=8d0abc&voteche ck=43c6428e

Response header:
HTTP/1.1 200 OK
Date: Thu, 12 Jan 2006 11:51:07 GMT
Server: Apache
X-Powered-By: PHP/4.2.3
Set-Cookie: Saregamapa_Vote=1; path=/
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

From the Java Applet:
POST /saregamapa/admin/srgma_vote_results.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*
Referer: http%3A%2F%2Fsifymax.com%2Fsaregamapa%2Fadmin%2Fsrgma_vote_page.php
Accept-La nguage: en-us
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: sifymax.com
Content-Length: 60
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: Cookie_Enable=1

vote=757251d3c100145201d&vote_code=7eb60f&voteche ck=43c6425b

Response header:
HTTP/1.1 200 OK
Date: Thu, 12 Jan 2006 11:49:49 GMT
Server: Apache
X-Powered-By: PHP/4.2.3
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
 
N

Nick Malik [Microsoft]

Rajiv Das said:
C#, WinXP SP2, VS 2005Beta2

I need to emulate the browser functionality wihin my app. I need to visit
a
web page , parse it and post back the results to another page. Everything
works fine, except that when the steps are performed from the browser, the
web server provides an extra set-cookie header in the second page's
response.
Here is a trace:

From the browser:
POST /saregamapa/admin/srgma_vote_results.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*
Referer: http://sifymax.com/saregamapa/admin/srgma_vote_page.php
A ccept-Language: en-us
Content-Type: application/x-www-form-urlencoded
XXXXXXXXXXXXXXX:++++++++++++++
User-Agen t: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
CLR 1.0.3705; Media Center PC 2.8; .NET CLR 2.0.50727)
Host: sifymax.com
Content-Length: 60
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: Cookie_Enable=1

vote=274331d3c115b6a2011&vote_code=8d0abc&voteche ck=43c6428e

Response header:
HTTP/1.1 200 OK
Date: Thu, 12 Jan 2006 11:51:07 GMT
Server: Apache
X-Powered-By: PHP/4.2.3
Set-Cookie: Saregamapa_Vote=1; path=/
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

From the Java Applet:
POST /saregamapa/admin/srgma_vote_results.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*
Referer:
http%3A%2F%2Fsifymax.com%2Fsaregamapa%2Fadmin%2Fsrgma_vote_page.php
Accept-La nguage: en-us
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: sifymax.com
Content-Length: 60
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: Cookie_Enable=1

vote=757251d3c100145201d&vote_code=7eb60f&voteche ck=43c6425b

Response header:
HTTP/1.1 200 OK
Date: Thu, 12 Jan 2006 11:49:49 GMT
Server: Apache
X-Powered-By: PHP/4.2.3
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html


What I find odd is that this is an urgent problem. The response headers
that come back, in both cases, are completely correct. If your app,
pretending to be a browser, cannot handle a cookie, you are in serious
trouble! You could always tell the remote server not to send you a cookie
by disabling cookies in the HTTP header (Cookie: Cookie_Enable=0)

Note that the Referer is URLEncoded in the applet example, but is not in the
..Net example. Also, your User Agent string is different. It is important,
if you are trying to get exactly the same results, to make sure that the
input is the same. That is because the server you are posting to may be
detecting the browser and responding differently based on the abilities of
the browser.

Hope this helps.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top