0

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....

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by LizR
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.