How to install HttpRequestHeader for HttpWebRequest?

I am trying to set the HttpRequestHeader for the HttpWebRequest as follows:

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 do I set the title?

+6
source share
1 answer

UserAgent is a property. Therefore, install it like this:

 HttpWebRequest request = new HttpWebRequest(); request.UserAgent = "Mozilla/4.0"; 
+9
source

All Articles