本帖最后由 liuyl 于 2016-8-27 17:50 编辑
[C#] 纯文本查看 复制代码
private void button1_Click(object sender, EventArgs e)
{
//参数类
item = new HttpItem()
{
URL = $"https://passport.ganji.com/login.php?callback=jQuery{GetTime()}&username={URLEncode(this.textBox1.Text)}&password={URLEncode(this.textBox2.Text)}",//URL
Method = "get",//URL 可选项 默认为Get
Encoding = Encoding.GetEncoding("utf-8"),
};
item.Header.Add("x-requested-with", "XMLHttpRequest");
//得到HTML代码
//string html = http.GetHtml(item);
HttpResult result = http.GetHtml(item);
cookie = result.Cookie;
//如果cookie存在说明登录成功
if (!string.IsNullOrEmpty(cookie))
{
//登录成功后访问一下[url=http://www.ganji.com/vip/account/edit_userinfo.php]http://www.ganji.com/vip/account/edit_userinfo.php[/url] 看看是不是真的登录成功了
item = new HttpItem()
{
URL = "http://www.ganji.com/vip/?_rid=0.46375988773070276",//URL 必需项
Method = "get",//URL 可选项 默认为Get
Cookie = cookie//当前登录Cookie
};
//得到HTML代码
result = http.GetHtml(item);
richTextBox1.Text = $"登录成功{result.Html}";
}
else
{
richTextBox1.Text = $"登录失败{result.Html}";
}
}
我的代码直接取出 url 在浏览器上执行是成功, 但是代码返回值 一直提示账号密码错误
|