zoukankan      html  css  js  c++  java
  • Asp.Net使用代理IP远程获取数据

    /// <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="" 表示不使用代理
  • 相关阅读:
    jq的遍历与杂项
    jq的事件
    jquery的效果
    jquery入门
    面向对象。对象的继承
    面向对象克隆对象
    面向对象this指向问题
    实例对象及原型链
    GCD多线程任务总结
    C语言链表的简单实用
  • 原文地址:https://www.cnblogs.com/webapi/p/5740323.html
Copyright © 2011-2022 走看看