HttpWebRequest的,以pretend就像一个浏览器请求? [英] HttpWebRequest to pretend like a browser request?

查看:114
本文介绍了HttpWebRequest的,以pretend就像一个浏览器请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code(在WinForm的应用程序),读取这个网址使用 HttpWebRequest.GetResponse()

I have some code (in a Winform app) that reads this URL using HttpWebRequest.GetResponse().

由于某些原因,它最近开始返回的 500 从我的应用程序需要时内部错误。结果
(响应包含一些HTML用于导航,但不具有的主要内容,我需要)

For some reason, it recently starts returning 500 Internal Error when requested from my app.
(The response contains some HTML for the navigations, but doesn't have the main content I need)

在Firefox / Chrome浏览器/ IE浏览器,它仍然是返回的 200 确定。

On Firefox/Chrome/IE, it is still returning 200 OK.

问题是我没有控制自己的code,我不知道它做什么的,导致从我的应用程序请求时,它打破了后端。

The problem is I don't have control over their code, I don't know what it does on the backend that causes it to break when requested from my app.

有没有一种方法,我可以pretend进行,比如说,从谷歌浏览器的请求? (只是为了避免错误)

Is there a way I can "pretend" to make the request from, say, Google Chrome? (just to avoid the error)

推荐答案

将<一个href=\"http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.useragent%28v=vs.110%29.aspx\"相对=nofollow> HttpWebRequest.UserAgent 属性设置为一个真正的浏览器的用户代理的值。

Set the HttpWebRequest.UserAgent property to the value of a real browser's user agent.

HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create("http://example.com");

webRequest.UserAgent = @"Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36";

这篇关于HttpWebRequest的,以pretend就像一个浏览器请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆