Thursday, July 3, 2014

[ StackOverflow.com ] Cannot set some HTTP headers when using System.Net.WebRequest

c# - Cannot set some HTTP headers when using System.Net.WebRequest - Stack Overflow
When I try to add a HTTP header key/value pair on a WebRequest object, I get the following exception:
This header must be modified using the appropriate property
I've tried adding new values to the Headers collection by using the Add() method but I still get the same exception...

webRequest.Headers.Add(HttpRequestHeader.Referer,"http://stackoverflow.com");
I can get around this by casting the WebRequest object to a HttpWebRequest and setting the properties such as httpWebReq.Referer ="http://stackoverflow.com", but this only works for a handful of headers that are exposed via properties.
I'd like to know if there's a way to get a finer grained control over modifying headers with a request for a remote resource.
Post a Comment

Know us

Our Team

Tags

Video of the Day

Contact us

Name

Email *

Message *