日期:2014-05-18  浏览次数:20779 次

“System.Net.HttpWebRequest”不包含“Host”的定义,怎么解决?



  //开始配置头信息
  req.Method = "POST";
  req.ContentLength = data.Length;
  req.ContentType = "Content-Type application/x-www-form-urlencoded";
  req.Host = "www.baidu.com";
  req.Accept = "Accept image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, application/vnd.ms-xpsdocument, application/x-ms-application, application/x-ms-xbap, application/xaml+xml, */*";
  req.Referer = "Referer https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F";




错误 4 “System.Net.HttpWebRequest”不包含“Host”的定义,并且找不到可接受类型为“System.Net.HttpWebRequest”的第一个参数的扩展方法“Host”(是否缺少 using 指令或程序集引用?)
E:\C#\项目1\yuanchuang\Form1.cs 479 17 yuanchuang


------解决方案--------------------
Host属性是.NET Framework4.0以后才有的。以前的版本无法使用。你可以
req.Headers.Add("Host","xxx")