http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 2418|回复: 1

[其他] httphelper登录失败的问题求助

[复制链接]
发表于 2013-3-24 22:31:41 | 显示全部楼层 |阅读模式
为什么我用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);
        }
    }
}


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-3-24 23:21:27 | 显示全部楼层
我只是简单的写写http的发送与接收,具体情况还要看设置的参数,vb和c#的写法是不同的,不能这样比较,你的代码基本无法调试,1.没有说要访问什么网站,也不知道要干什么,只是见到你说,不能有,有问题,如果楼主感觉你代码不方便放论坛,那就发群里,如果群里也不方便那就没办法帮你了,另外你用的类版本太老了,希望更新
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-3 01:54

© 2014-2021

快速回复 返回顶部 返回列表