|
发表于 2013-10-3 11:30:00
|
显示全部楼层
写了下,但有一步的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;
- namespace renren
- {
- public partial class Form1 : Form
- {
- string LoginCookie = "";
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- HttpHelper http = new HttpHelper();//HttpHelper.cs为4.0以下版本,代码未作任何改动.
- HttpItem item = new HttpItem()
- {
- URL = "http://hi.mop.com/SysHome.do",
- Encoding = null,
- Method = "GET",
- Cookie = "",
- UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT6.0)",
- Referer = "",
- };
- HttpResult result = http.GetHtml(item);
- LoginCookie = result.Cookie + ";mopst_unique=" + GetTime();
- item = new HttpItem()
- {
- URL = "http://login.hi.mop.com/Login.do",
- Method = "POST",
- Cookie = LoginCookie,
- Referer = "http://hi.mop.com/SysHome.do",
- Postdata = "nickname=%E9%9B%85%E7%A0%BE%E7%91%AD%E5%8F%A3&password=123123&origURL=http%3A%2F%2Fhi.mop.com%2FSysHome.do&loginregFrom=index&ss=10101",
- Allowautoredirect=false,
- };
- //以上Cookie操作正常
- result = http.GetHtml(item);
- string LocationUrl = result.Html;
- LoginCookie += ";"+result.Cookie;
- item = new HttpItem()
- {
- URL = LocationUrl,
- Method = "GET",
- Cookie = LoginCookie,//此处Cookie的值正常,但通过抓包发现,Cookie并未提交出去,造成返回结果是回到登录页面:http://login.hi.mop.com/Login.do
- Referer = "http://hi.mop.com/SysHome.do",
- };
- result = http.GetHtml(item);//此处请求时Cookie为什么不提交?
- textBox1.Text = LoginCookie+"\r\n"+result.Html;
- }
- private string GetTime()//时间戳
- {
- DateTime timeStamp = new DateTime(1970, 1, 1);
- long a = (DateTime.UtcNow.Ticks - timeStamp.Ticks) / 10000;
- Random ra = new Random();
- return a.ToString() + ra.Next(1000, 10000).ToString();
- }
- }
- }
复制代码 晕,咋不能加附件?
|
|