good morning, I need your help.
I have an error with WebHeaderCollection class when trying to add the header "User-Agent" jumping me the error in visual studio is as follows:
"This header must be modified With The right property
My code is as follows and the fault is on the third line.
private static readonly WebHeaderCollection Headers = new WebHeaderCollection()
{
{"User-Agent", "Custom-User-Agent"}, // <<=== ERROR??
{"Cookie", "MyCookie"},
{"application", "netconnect"}
};
private static void Start(int nRequests)
{
WebRequest.DefaultWebProxy = null;
for (var i = 0; i < nRequests; ++i) {
SendRequest();
}
}
private static bool SendRequest()
{
var request = HttpWebRequest.Create("URL");
request.Headers = Headers;
using (var response = (HttpWebResponse)request.GetResponse()) {
//Returns boolean indicating success
return response.StatusCode == HttpStatusCode.OK;
}
}
Any solution to solve this? Thank you very much!