Is there a way to explicitly set the hosts header on HttpWebRequest

  • Thread starter Thread starter Young Cho
  • Start date Start date
Y

Young Cho

I am trying to use HTTP 1.0 and the HttpWebRequest.Create() to POST XML
data. Is there a way to explicitly set the hosts header?

Thank you!
Young.
 
However, the following code will result in the exception given below:

HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(https://www.myserver.com);
req.Method = "POST";
req.ContentType = "text/xml";
req.Headers.Add("Host: www.myserver.com");
....


An unhandled exception of type 'System.ArgumentException' occurred in
System.dll
Additional information: This header must be modified with the appropriate
property.

However, the HttpWebRequest does not have a "Host" property.

Y.
 
Back
Top