How to edit request host headers in c# through web request?
When i'm trying to edit the Host key on Request.Headers under console application i'm getting exception that says:
The 'Host开发者_如何学Go' header cannot be modified directly.
Parameter name: name
So how can i change it?
As you've seen the .Net Fx does not allow to edit the host header, but since .Net Fx 4.0 there is a seperate 'Host' definition on the HttpWebRequest object. You can use it like this:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://127.0.0.1/");
request.Host = "yourdomain.com";
Hope that helps you out.
精彩评论