コード例 #1
0
ファイル: Form1.cs プロジェクト: xuanjibbs/HttpCodeLib
        private void btnProxy_Click(object sender, EventArgs e)
        {
            string    url  = "http://1111.ip138.com/ic.asp"; //请求地址
            string    ip   = "127.0.0.1:8888";               //设置代理IP地址
            HttpItems item = new HttpItems();

            item.URL     = url;
            item.ProxyIp = ip;
            //如果代理服务器需要用户名与密码请参考此设置
            //item.ProxyUserName = "******";//如果代理服务器需要用户名
            //item.ProxyPwd = "密码";//如果代理服务器需要密码
            HttpResults hr = http.GetHtml(item);
            // hr.Html; 请求具体结果
            Wininet winet = new Wininet();
            //Post
            string postdata = "GetHtmlPro 如果传入PostData参数则认为当前是Post请求";
            string Posthtml = winet.GetDataPro(winet.GetHtmlPro(url, postdata, ip));
            //Get
            string Gethtml = winet.GetDataPro(winet.GetHtmlPro(url, "", ip));
            //使用代理请求图片时
            Image img = winet.GetImage(winet.GetHtmlPro("图片URL", "", ip));
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: 2stack/bto
        private void btnWininetGet_Click(object sender, EventArgs e)
        {
            string cookie = "A8tI_2132_saltkey=HdIon04N;expires=Tue;Max-Age=900;path=/;A8tI_2132_lastvisit=1480405220;A8tI_2132_lastact=1480408820%09member.php%09logging;A8tI_2132_adv_gid=7;A8tI_2132_ulastactivity=1480408820%7C0;A8tI_2132_auth=bba383AA%2FEgQ31nQUX0gmmg%2FL7TYk%2BtIXNncgFdMGS2cm6b%2FuzIrFNslJN6BFHyZAEb2MbWhnZN5K%2B3RdoNhy8bQKAGg2A;A8tI_2132_activationauth=deleted;A8tI_2132_pmnum=deleted;A8tI_2132_staticlogin=1;A8tI_2132_lastcheckfeed=10214715%7C1480408820;A8tI_2132_checkfollow=1;A8tI_2132_lip=8.8.8.8%2C1480408820;A8tI_2132_1qaz21=ui6m3b0%2FKjh6YYC%2F4FTC6Q%3D%3D;A8tI_2132_1qaz341=WwCmKj5xZWDLem9d1mwpLP0RW9arQbA7;visid_incap_625395=TXa4G5X2RUa3zj1TVzKJ5yw+PVgAAAAAQUIPAAAAAACv84vX3Xe9T0q0L4AsoOZb;Domain=.clubxgirl.net;nlbi_625395=RbmaXE+g3EQZBXqJJJkW2AAAAAAQQErbYd42BK0qpySdqNFU;incap_ses_541_625395=q/D/AujD33CnmH/ftASCB/M+PVgAAAAAUPoxBXvUztf3dgqhk8dfUA==;___utmvmfauiSZs=wSgXbVmbcGm;___utmvafauiSZs=YEY\u0001gsNf;___utmvbfauiSZs=IZM XqdOLalt: Kto";
            string str1   = new XJHTTP().ClearCookie(cookie);
            Random r      = new Random();
            string str    = "";
            //str=wnet.GetData("http://www.baidu.com"); //正常请求.


            StringBuilder header = new StringBuilder();

            header.AppendLine("User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0");
            header.AppendLine("Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            header.AppendLine("Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");
            header.AppendLine("Accept-Encoding:gzip, deflate");
            header.AppendLine("Cookie:" + "123=123");
            header.AppendLine("Connection:keep-alive");
            str = wnet.GetDataPro(wnet.GetHtmlPro("http://www.msdn5.com", "", "", true, header.ToString()));
            //wnet.WininetTimeOut = 5000;
            //string str1 = wnet.GetData("http://www.google.com"); //测试超时,超时后返回长度为0的字符串
            txtInfo.Text = str;
            //MessageBox.Show(str1);
        }