开发者

How to edit request host headers in c# through web request?

开发者 https://www.devze.com 2023-03-09 05:28 出处:网络
When i\'m trying to edit the Host key on Request.Headers under console application i\'m getting exception that says:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消