开发者

How do I set the HttpRequestHeader for a HttpWebRequest?

I'm trying to set the HttpRequestHeader for a HttpWebRequest like so:

new HttpWebRequest().开发者_JS百科Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0");

But I get an exception: System.ArgumentException: This header must be modified using the appropriate property.

How should I be setting the header?


UserAgentis a property. So set it like this:

HttpWebRequest request = new HttpWebRequest();
request.UserAgent = "Mozilla/4.0";
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜