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 aWebRequest
object, I get the following exception:
This header must be modified using the appropriate propertyI've tried adding new values to theHeaders
collection 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 aswebRequest.Headers.Add(HttpRequestHeader.Referer,"http://stackoverflow.com");
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.
No comments:
Post a Comment