1

I am trying to change the value of "Host" parameters in the HttpWebRequest headers but I am getting error below:

"This header must be modified with the appropriate property. at System.Net.WebHeaderCollection.ThrowOnRestrictedHeader(String headerName)"

I am trying to use the following code:

HttpWebRequest hbWebRequest = (HttpWebRequest)System.Net.HttpWebRequest.Create(WebService);
hbWebRequest.Method = "POST";
hbWebRequest.Headers["Host"] = WebURL;

2 Answers 2

2

Found this link helpful http://blogs.msdn.com/b/ncl/archive/2009/07/20/new-ncl-features-in-net-4-0-beta-2.aspx

which gives the following solution

var request = WebRequest.Create("http://127.0.0.1/") as HttpWebRequest; 
request.Host = "contoso.com"; 
var response = request.GetResponse();
Sign up to request clarification or add additional context in comments.

Comments

1

In .NET Framework 4.0 you can use the Host property of the HttpWebRequest class.

hbWebRequest.Host = WebURL;

Edit: Possible duplicate of this question.

1 Comment

Hi David, Sorry to say but hbWebRequest.Host is not coming in Compact Framework.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.