开发者

How come I am getting different responses on browser than the server

Here is an example website

http://us.blizzard.com/store/browse.xml?f=c:5,c:33

When I inspect the response in Firefox it is application/xhtml

When I make a request to the same url server side with the following headers

var request = (HttpWebRequest)WebRequest.Create(url);
var cookieContainer = new CookieContainer();

request.CookieContainer = cookieContainer;
request.UserAgent = @"Moz开发者_JAVA百科illa/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5";
request.Method = "GET";
request.AllowAutoRedirect = true;
request.Timeout = 15000;

The response is application/xml

Any Ideas?

Thanks


Try including Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 to your request.

request.Accept = @"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

EDIT:

Try to replicate the request from Firefox.

I tried this (I used chrome + chrome dev tools to get the headers)

        request.CookieContainer = cookieContainer;
        request.UserAgent = @"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30";
        request.Accept = @"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        request.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
        request.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
        request.Headers.Add("Accept-Language", "en-US,en;q=0.8");

        request.Method = "GET";
        request.AllowAutoRedirect = true;
        request.Timeout = 15000;

and got back application/xhtml+xml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜