c#多线程下载例子
c#多线程下载例子
例子越简单越好,能完成下载网页,读取网页流就可以了。
读取网页内容代码如下:
public string ReadUrlContent(string rUrl) { // used to build entire input StringBuilder sb = new StringBuilder(); // 请求该页面 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(rUrl); // 获取返回的数据(通过相应) HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //将读取到的数据放入到流里面 Encoding enc = Encoding.GetEncoding("GB2312"); //如果是乱码就改成 utf-8 / GB2312 StreamReader loResponseStream = new StreamReader(response.GetResponseStream(), enc); sb.Append(loResponseStream.ReadToEnd()); loResponseStream.Close(); return sb.ToString(); }