Anytime you're changing the headers of an HttpWebRequest
, you need to use the appropriate properties on the object itself, if they exist. If you have a plain WebRequest
, be sure to cast it to an HttpWebRequest
first. Then Referrer
in your case can be accessed via ((HttpWebRequest)request).Referrer
, so you don't need to modify the header directly - just set the property to the right value. ContentLength
, ContentType
, UserAgent
, etc, all need to be set this way.
IMHO, this is a shortcoming on MS part...setting the headers via Headers.Add()
should automatically call the appropriate property behind the scenes, if that's what they want to do.