POST phpwind 登陆

private void button2_Click(object sender, EventArgs e)
      {
          string FormURL = "http://bbs.mydigit.cn/login.php";
          string list2 = "?foward=&jumpurl=http://bbs.mydigit.cn&step=2&lgt=0&pwuser=hdl&pwpwd=hdl&question=0&customquest=&answer=&hideid=1&cktime=31536000";

          System.Net.CookieContainer cook = new System.Net.CookieContainer();
          string html = Login(FormURL, list2, out cook);
          FormURL = "http://bbs.mydigit.cn/jobcenter.php?action=punch&verify=ce2c8f43&nowtime=2309477852&verify=ce2c8f43&step=2";
          html = HttpRequestHelp.getPage(FormURL, "", ref cook);
          html = Login(FormURL, list2, out cook);

          //这里的cookies,需要从哪里获得????
          //问题补充  2009-07-20 18:37
          //request.Headers.Add("Accept-Encoding", "gzip, deflate");

          //没事了。去掉这句,就不乱码了。

      }

      private static string Login(string FormURL, string FormData, out CookieContainer container)
      {
          Encoding encoding = new ASCIIEncoding();
          byte[] data = encoding.GetBytes(FormData);

          HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FormURL);
          request.Method = "POST";
          request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
          request.Referer = FormURL;
          request.Headers.Add("Accept-Language", "zh-cn");
          request.ContentType = "application/x-www-form-urlencoded";
          request.Headers.Add("UA-CPU", "x86");
          request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
          request.ContentLength = data.Length;

          //应该主要就是cookies的问题,下面方法无效。
          if (container == null || container.Count == 0)
          {
              container = new CookieContainer();
              container.GetCookies(new Uri(FormURL));
          }
          request.CookieContainer = container;
          Stream newStream = request.GetRequestStream();
          System.Type type = newStream.GetType();
          newStream.Write(data, 0, data.Length);
          newStream.Close();

          HttpWebResponse response = (HttpWebResponse)request.GetResponse();

          Stream responsestr = response.GetResponseStream();
          StreamReader responsesr = new StreamReader(responsestr, Encoding.GetEncoding("GB2312"));

          //获得测试页面无效,内容为不知编码格式的数据,不是GB2312、UTF8、Unicode
          string html = responsesr.ReadToEnd();
          responsestr.Close();
          responsesr.Close();
          return html;
      }

转载于:https://www.cnblogs.com/hdl217/archive/2011/07/01/2096031.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值