开发者

How do I set the HttpRequestHeader for a HttpWebRequest?

开发者 https://www.devze.com 2022-12-24 10:31 出处:网络
I\'m trying to set the HttpRequestHeader for a HttpWebRequest like so: new HttpWebRequest().开发者_JS百科Headers.Add(HttpRequestHeader.UserAgent, \"Mozilla/4.0\");

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

精彩评论

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