Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the HttpRequestHeader for a HttpWebRequest?

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

new HttpWebRequest().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?

like image 765
Mr. Flibble Avatar asked Mar 18 '10 15:03

Mr. Flibble


1 Answers

UserAgentis a property. So set it like this:

HttpWebRequest request = new HttpWebRequest();
request.UserAgent = "Mozilla/4.0";
like image 73
Simon Linder Avatar answered Nov 11 '22 12:11

Simon Linder