When I try to add a HTTP header key/value pair on a
WebRequestobject, I get the following exception:
This header must be modified using the appropriate property
I’ve tried adding new values to the
Headerscollection by using the Add() method but I still get the same exception…
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.