English 中文(简体)
为什么我在浏览器上得到的响应与服务器不同
原标题:How come I am getting different responses on browser than the server
  • 时间:2011-05-31 22:52:58
  •  标签:
  • c#
  • asp.net

以下是一个示例网站

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

当我在Firefox中检查响应时,它是application/xhtml

当我用以下标题向同一个url服务器端发出请求时

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

request.CookieContainer = cookieContainer;
request.UserAgent = @"Mozilla/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;

响应为application/xml

有什么想法吗?

谢谢

最佳回答

尝试包含Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

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

编辑:

尝试从Firefox复制请求。

我尝试过这个(我使用chrome+crome开发工具来获取标题)

        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;

并返回application/xhtml+xml

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签