#region 根据URL读取网络内容
/// <summary>
/// 根据URL读取网络内容,调用时根据网页手动传入编码,如:gb2312,utf8
/// </summary>
/// <param name="url"></param>
/// <returns>Error说明抓取错误</returns>
public static string GetRemoteHtmlCode(string url,string encode)
{
string HtmlCode = "";
HttpWebRequest wrequest = (HttpWebRequest)WebRequest.Create(url);
try
{
HttpWebResponse wresponse = (HttpWebResponse)wrequest.GetResponse();
Stream stream = wresponse.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(encode));
HtmlCode = reader.ReadToEnd();
reader.Close();
wresponse.Close();
}
catch
{
HtmlCode = "Error";
}
return HtmlCode;
}
#endregion
可以实现吗
Encoding.Default 不是UTF-8吧!
Encoding.GetEncoding("UTF-8"); 或者 Encoding.UTF8Encoding
你都知道是UTF8了怎么还用Default呢,直接用Encoding.UTF8不就OK了吗?
2楼。呵呵
Encoding.Default = Encoding.UTF - 16