HttpWebRequest Get 数据 显示乱码 类似正长方形
本帖最后由 HYMR101 于 2013-07-01 10:16:24 编辑
private string GetPost(string Url)
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(Url);
req.Method = "GET";
req.Accept = "application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/QVOD, application/QVOD, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQDownload 691; CIBA; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET4.0C; .NET4.0E; InfoPath.2)";
WebHeaderCollection head = new WebHeaderCollection();
req.Headers = head;
req.KeepAlive = true;
req.Timeout = 30000;
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
Stream stm = res.GetResponseStream();
StreamReader sr = new StreamReader(stm, Encoding.GetEncoding("utf-8"));//
string endstr = sr.ReadToEnd();
string sk = sr.ReadLine();
string skk = sr.ToString();
res.Close();
stm.Close();
sr.Close();
return endstr;