Mr. Flibble
Mr. Flibble

Reputation: 27003

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?

Upvotes: 6

Views: 10308

Answers (1)

Simon Linder
Simon Linder

Reputation: 3428

UserAgentis a property. So set it like this:

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

Upvotes: 9

Related Questions