首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

模拟登陆顺利后 无法保存COOKIE

2013-08-26 
模拟登陆成功后 无法保存COOKIEusing Systemusing System.Collections.Genericusing System.ComponentMo

模拟登陆成功后 无法保存COOKIE


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Windows.Documents;

namespace ID_中心登陆
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form.CheckForIllegalCrossThreadCalls = false;
            Thread thread = new Thread(new ThreadStart(login));
            thread.Start();
        }

        public void login()
        {
            string cookie = "";
            string content = Http.httpGet("http://check.ptlogin2.qq.com/check?uin=" + txtuser.Text + "&appid=1006102&js_ver=10021&js_type=0&login_sig=HdN3svu2cSDSrocIOprFaBOvvEpW5-gD2qXdvRAylcMd8e-ziEHKOqww376ZXz3r&u1=http%3A%2F%2Fid.qq.com%2Findex.html&r=0.751604591311832", cookie, ref cookie, "http://id.qq.com/index.html");
            Debug.Print(content);
            string code = Http.Content(content, "','", "','");
            string uin = Http.Content(content, "\\x", "')");
            if (code.Length > 4)
            {
                Stream sr = Http.httpPic("http://captcha.qq.com/getimage?&uin=" + txtuser.Text + "&aid=1006102&0.9609332418713563", cookie, ref cookie, "http://captcha.qq.com/");


                pictureBox1.Image = Image.FromStream(sr);
                while (txtcode.Text.Length < 4)
                {
                    Application.DoEvents();
                    Thread.Sleep(500);
                }
                code = txtcode.Text;
                pictureBox1.Image = null;
                txtcode.Text = null;
                
            }
            string password = Http.GetPassword(uin,txtpass.Text,code);
            string login = Http.httpGet("http://ptlogin2.qq.com/login?u=" + txtuser.Text + "&p=" + password + "&verifycode=" + code + "&aid=1006102&u1=http%3A%2F%2Fid.qq.com%2Findex.html&h=1&ptredirect=1&ptlang=2052&from_ui=1&dumy=&fp=loginerroralert&action=9-90-187303&mibao_css=&t=2&g=1&js_type=0&js_ver=10021&login_sig=HdN3svu2cSDSrocIOprFaBOvvEpW5-gD2qXdvRAylcMd8e-ziEHKOqww376ZXz3r", cookie, ref cookie, "http://ptlogin2.qq.com");
            Debug.Print(login);
            //textBox1.Text = login;
            if (login.IndexOf("登录成功", 0) != -1)
            {
                textBox1.Text += "登陆成功!";
            }
            else
            {
                textBox1.Text += "登陆失败!";


            }
            textBox1.Text += "你的用户名为:" + Http.Content(login, "', '", "')"); ;




[解决办法]
 private CookieContainer cookie = new CookieContainer();


 在你的Http类中 

      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

       request.CookieContainer = cookie;

热点排行