|
为什么我用httphelper登录个别cms系统网站后台会登陆不了
但是像百度这种网站确实可以登录
我post的信息绝对是正确的,因为我用VB做的程序可以登录成功
代码如下:修改的本站登录百姓网的源代码
/// <summary>
/// 更新网址:http://www.sufeinet.com/thread-3-1-1.html
/// 修改日期:2012-12-09
/// </summary>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DotNet.Utilities;
using System.Text.RegularExpressions;
using System.Web;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string cookie = "";
//创建HTTP访问类对象
HttpHelper http = new HttpHelper();
HttpItem item = null;
public static string URLDecode(string text)
{
return HttpUtility.UrlDecode(text, Encoding.GetEncoding("utf-8"));
}
public static string URLEncode(string text)
{
return HttpUtility.UrlEncode(text, Encoding.GetEncoding("utf-8"));
}
private void button1_Click(object sender, EventArgs e)
{
//参数类
item = new HttpItem()
{
URL = "http://localhost/admin/admin_login.asp?action=login",//URL 必需项
Encoding = "gb2312",//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Referer = "http://ocalhost/admin/admin_login.asp",
Method = "post",//URL 可选项 默认为Get
UserAgent = "Microsoft URL Control - 6.01.9782",
ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
Postdata = "AdminName=admin&PassWord=ladmin&checkcode=&submit.x=42&submit.y=17"
};
//得到HTML代码
string html = http.GetHtml(item);
cookie = item.Cookie;
//如果cookie存在说明登录成功
if (!string.IsNullOrEmpty(cookie))
{
//登录成功后访问一下http://www.ganji.com/vip/account/edit_userinfo.php 看看是不是真的登录成功了
item = new HttpItem()
{
URL = "http://localhost/Admin/Index.asp",//URL 必需项
Encoding = "gb2312",//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Method = "get",//URL 可选项 默认为Get
Cookie = cookie//当前登录Cookie
};
//得到HTML代码
html = http.GetHtml(item);
//正则验证余额是否存在
if (Regex.IsMatch(html, @"\d{1,10}.\d{1,2}</em>元</span>"))
{
richTextBox1.Text = "登录成功" + html;
}
else
{
richTextBox1.Text = "登录失败" + html;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
//登录成功后访问一下任意网址测试
item = new HttpItem()
{
URL = textBox3.Text.Trim(),//URL 必需项
Encoding = "gbk",//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Method = "get",//URL 可选项 默认为Get
Cookie = cookie//当前登录Cookie
};
//得到HTML代码
richTextBox1.Text = http.GetHtml(item);
}
}
}
|
|