我正在尝试更改HttpWebRequest标题中“主机”参数的值,但我收到以下错误:
“必须使用相应的属性修改此标头。在System.Net.WebHeaderCollection.ThrowOnRestrictedHeader(String headerName)”
我正在尝试使用以下代码:
HttpWebRequest hbWebRequest = (HttpWebRequest)System.Net.HttpWebRequest.Create(WebService);
hbWebRequest.Method = "POST";
hbWebRequest.Headers["Host"] = WebURL;
答案 0 :(得分:1)
答案 1 :(得分:1)
发现此链接有用 http://blogs.msdn.com/b/ncl/archive/2009/07/20/new-ncl-features-in-net-4-0-beta-2.aspx
给出了以下解决方案
var request = WebRequest.Create("http://127.0.0.1/") as HttpWebRequest;
request.Host = "contoso.com";
var response = request.GetResponse();