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.
Accept
doesn't exist as a property on WebRequest
, but it does exist on HttpWebRequest
.
HttpWebRequest request = (HttpWebRequest) Request.Create("http://example.com");
request.Accept = "*/*";
Even though you were previously using as HttpWebRequest
(and I'd strongly suggest preferring casting instead), your variable was declared to be of type WebRequest
, which is why it wouldn't compile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With