获取网络中的一个文本用string数组存储

留着备用.
[cce_cs]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;

namespace OpenURL
{
    static class GetURL
    {
        static Encoding enc = Encoding.GetEncoding("GB2312");
        /// <summary>
        /// 获取文本
        /// </summary>
        /// <param name="txturl">URL链接</param>
        /// <returns>获取到的数组,每行一个</returns>
        public static string[] GetUrlList(string txturl)
        {
            try
            {
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(txturl);
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                StreamReader reader = new StreamReader(res.GetResponseStream(), enc);
                string data1 = reader.ReadToEnd();
                res.Close();
                reader.Close();
                string[] urlstr = new string[data1.Split('n').Length];
                for (int i = 0; i < data1.Split('n').Length; i++)
                {
                    urlstr[i] = data1.Split('n')[i];
                }
                return urlstr;
            }
            catch (Exception ex)
            { System.Windows.Forms.MessageBox.Show(ex.Message); }
            return null ;
        }
    }
}

[/cce_cs]
 

1 Reply to “获取网络中的一个文本用string数组存储”

回复 深圳男科医院 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据