/// <summary>
    /// 远程获取数据
    /// </summary>
    /// <param name="url">url</param>
    /// <param name="code">编码</param>
    /// <param name="ProxyStr">代理IP,格式:10.20.30.40:8888</param>
    /// <returns></returns>
    public static string SendUrl(string url, Encoding code, string ProxyStr)
    {
        string html = string.Empty;
        try
        {
            HttpWebRequest WebReques = (HttpWebRequest)HttpWebRequest.Create(url);
            WebReques.Method = "GET";
            WebReques.Timeout = 20000;
            if (ProxyStr.Length > 0)
            {
                WebProxy proxy = new WebProxy(ProxyStr, true);
                WebReques.Proxy = proxy;
            }

            HttpWebResponse WebRespon = (HttpWebResponse)WebReques.GetResponse();
            if (WebRespon != null)
            {
                StreamReader sr = new StreamReader(WebRespon.GetResponseStream(), code);
                html = sr.ReadToEnd();
                sr.Close();
                sr.Dispose();
                WebRespon.Close();
            }
        }
        catch
        {
    html = “err”;
        }
        return html;
    }
//ProxyStr="" 表示不使用代理

相关文章:

  • 2022-02-23
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
猜你喜欢
  • 2021-09-18
  • 2022-12-23
  • 2021-06-20
  • 2021-10-11
  • 2021-10-28
  • 2022-12-23
  • 2021-07-13
相关资源
相似解决方案