Hi to all I'm trying to change the headers of a request, I'm trying to simulate a request from different browsers, languages...
The problem is when I try to change the headers I receive an exception(see below), this is the code I'm using:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Set(HttpRequestHeader.UserAgent, "string");
request.Headers.Set(HttpRequestHeader.Accept, "string");
request.Headers.Set(HttpRequestHeader.Referer, "string");
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "string");

Is this possible to do?
Thanks in advanced

Exception:
"System.ArgumentException: This header must be modified using the appropriate property.\r\nParameter name: name\r\n at System.Net.WebHeaderCollection.ThrowOnRestrictedHeader(String headerName)\r\n at System.Net.WebHeaderCollection.Set(String name, String value)\r\n at System.Net.WebHeaderCollection.Set(HttpRequestHeader header, String value)\r\n at....

Well if you look at what its told you and the properties of the request object, the answer should slap you in the face

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.