localhost测试-- post 流程 小结--备忘

 

流程
第一部 正常 方式 访问 需要登录的页面 抓包分析
  1 提交的地址 / 分析源码
  2 提交的数据构成 --比如含有 别的 网页hash 客户端其他数据
  3 取验证码的地址
  4 cookies
第二部
  1 get 方式 访问 登录 页面
            requestWeb = WebRequest.Create("http://localhost/168/index.php?s=Admin-Login") as HttpWebRequest;
            requestWeb.Method = "Get";

            responseWeb = requestWeb.GetResponse() as HttpWebResponse;
            StreamReader dataresponse = new StreamReader(responseWeb.GetResponseStream(), Encoding.UTF8);
            string data = dataresponse.ReadToEnd(); //读取返回的流
目的一: 取出提交数据中需要使用的hash值 之类 ..
           string data2 = "value=\""; // \" 代表显示"   通过关键字符查找 拿出32位的hash值之类吧
           textBox_code.Text = data.Substring(data.IndexOf(data2), 39).Substring(7);  //使用indexof 和substring一般可以搞定
           //取出 后 保存到文本框
目的二: 拿出建立连接时的cookies保存起来
          string cookies = responseWeb.Headers.Get("Set-Cookie"); //获取该连接的cookies
          cookies = cookies.Split(';')[0]; //分割出里面的sesionid
          textBox_cookies.Text = cookies; //保存到文本框
          requestWeb = null;
          responseWeb = null;
第三部
     利用获取保存的cookies 来 get访问取验证码的地址 并且显示出验证码
     http://localhost/168/index.php?s=Admin-Login-Vcode 是取验证码的地址
            CookieContainer cc = new CookieContainer();
            cc.SetCookies(new Uri("http://localhost/168/index.php?s=Admin-Login-Vcode"), cookies);  //将刚才连接保存的cookies 设置加入
            requestWeb = WebRequest.Create("http://localhost/168/index.php?s=Admin-Login-Vcode") as HttpWebRequest;
            requestWeb.CookieContainer = cc; // 带cookies 进行get访问
            requestWeb.Method = "Get";

            responseWeb = requestWeb.GetResponse() as HttpWebResponse;
            Bitmap img = new Bitmap(responseWeb.GetResponseStream());  //获取验证码图片 保存到pic框中显示
            pictureBox1.Image = img;
            responseWeb = null;
            requestWeb = null;
第四部
      还是利用刚才保存的cookies 来进行POST 登陆地址
http://localhost/168/index.php?s=Admin-Login-Check 为post提交地址
            CookieContainer cc = new CookieContainer();
            cc.SetCookies(new Uri("http://localhost/168/index.php?s=Admin-Login-Check"), textBox_cookies.Text.ToString());  // 将保存在文本框
的cookies 设置到 post地址
            string postdata = "user_name=admin&user_pwd=admin&verify=" + textBox_验证码.Text + "&__hash__=" + textBox_code.Text + "&submit.x=25&submit.y=15"; //构建提交的数据  使用到 取得的验证码 输入到验证码框 和 前面获取的hash值
            requestWeb = HttpWebRequest.Create("http://localhost/168/index.php?s=Admin-Login-Check") as HttpWebRequest;
            requestWeb.Method = "POST";
            requestWeb.CookieContainer = cc; // 设置带cookies 来post
            requestWeb.ContentType = "application/x-www-form-urlencoded";
            StreamWriter datawriter = new StreamWriter(requestWeb.GetRequestStream(), Encoding.Default);
            datawriter.Write(postdata);   //写入post提交数据
            datawriter.Flush();
            //----下面为 返回的页面

            responseWeb = requestWeb.GetResponse() as HttpWebResponse;
            StreamReader datareader = new StreamReader(responseWeb.GetResponseStream(), System.Text.Encoding.UTF8);
            textBox_Post返回.Text = datareader.ReadToEnd();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值