tags:

views:

96

answers:

1

I used HttpClient and GetMethod to get the page source of the URL :

http://www.google.com/finance?chdnp=1&chdd=1&chds=1&chdv=1&chvs=Logarithmic&chdeh=0&chdet=1264263288788&chddm=391&chddi=120&chls=Ohlc&q=NSE:.NSEI&

But somehow I always end up getting page source of :

http://www.google.com/finance?q=NSE:.NSEI

Can anyone tell me why and how to get page source of the former URL?

+1  A: 

I'm going to go out on a limb here and assume that what's going on is that your HttpClient implementation handles HTTP redirects internally and so when you call GetMethod on the first URL, the server (google.com) is probably sending back an HTTP redirect (302, or 301) response for the second URL which is what you end up getting back.

The reason for that is probably that the first URL requires some sort of cookie which you're not providing when you make your request. The best way to determine exactly what happens when you make the request that way is to use a tool such as WireShark or Fiddler to analyse the HTTP request/response sequence from your HttpClient and that of a normal request made using FireFox or IE and see what exactly is different.

Miky Dinescu
Asaph
Well, *YOU* checked it. But, depending on what platform he's using or how HttpClient makes the request, the server may be responding with a different response. The thing is he needs to do the test himself, using the same computer (assuming it's a computer) and determine what the difference is between the HttpClient request and another client's request using one of the tools I suggested. The answer most likely lies in the HTTP traffic flow (wrong headers, missing cookies etc.)
Miky Dinescu
@Miky D: I didn't set any cookies at all with my test request.
Asaph

related questions