c# - Error with WebHeaderCollection class when trying to add the header "User-Agent" -


good morning, need help.

i have error webheadercollection class when trying add header "user-agent"   jumping me error in visual studio follows:

"this header must modified right property

my code follows , fault on 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;      (var = 0; < 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 solve this? thank much!

as msdn said:

some common headers considered restricted , either exposed directly api (such content-type) or protected system , cannot changed.

you may specify ua on httpwebrequest:

request.useragent = "custom-user-agent" 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -