I am using .Net 4 and VS express 2010.
I could make my post request but I cant set some of the headers.
Below code work fines
WebRequest Request = Request.Create("http://example.com") as HttpWebRequest;
Request.Method = "POST";
Request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
Request.Headers.Set("Accept-Encoding", "gzip, deflate");
The problems is that I cant set other headers like “Accept”,”UserAgent”,”Referer”,”Connection”
I had tried the following ways but fail
Request.Accept = "*/*";
Request.Headers.Set("Accept", "*/*");
For the first line, the Accept property doesn’t exist
while for the second line, the header need to be edited with a proper method or property.
I am a rookie and I had searched on google and stackoverflow.
If you don’t know how to solve it, pointing out any direction in fixing this like reinstalling something would be really appreciated.
Acceptdoesn’t exist as a property onWebRequest, but it does exist onHttpWebRequest.Even though you were previously using
as HttpWebRequest(and I’d strongly suggest preferring casting instead), your variable was declared to be of typeWebRequest, which is why it wouldn’t compile.