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.
 
Yes, HttpWebRequest has Headers property, to which you can add
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top