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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 5484|回复: 6

[其他] phpwind论坛登陆问题

[复制链接]
发表于 2014-4-16 15:54:40 | 显示全部楼层 |阅读模式
先把代码贴出来,问题描述在代码的注释上,哪个兄弟帮帮忙,看下到底错在哪儿,源程序码也附上,谢谢了


[C#] 纯文本查看 复制代码
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;
using DotNet4.Utilities;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }




        private string addpost(string a, string b, string c)
        {
            if (a == null)
            {
                return (b + "=" + c);
            }
            else
            {
                return (a + "&" + b + "=" + c);
            }

        }


        private void button1_Click(object sender, EventArgs e)
        {
            HttpHelper http = new HttpHelper();






            string p1 = null;

            p1 = addpost(p1, "jumpurl", "http://bbs.mydigit.cn/");
            p1 = addpost(p1, "step", "2");
            p1 = addpost(p1, "ajax", "1");
            p1 = addpost(p1, "pwuser", user);
            p1 = addpost(p1, "pwpwd", pass);
            p1 = addpost(p1, "lgt", "0");



          HttpItem item = new HttpItem()
            {
                URL = "http://bbs.mydigit.cn/login.php",   
                Method = "post",   
                IsToLower = false, 

                Referer = "",  
                Postdata = p1,
                Timeout = 100000,    
                ReadWriteTimeout = 30000,   
                UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",   
                ContentType = "application/x-www-form-urlencoded",
                Allowautoredirect = true,  

                ProxyIp = "",  

                ResultType = ResultType.String
            };
          HttpResult result = http.GetHtml(item);

          //登陆成功   返回值<?xml version="1.0" encoding="gbk"?><ajax><![CDATA[success        [url]http://bbs.mydigit.cn/[/url]]]></ajax>

           string html = result.Html;
           string  cookie = result.Cookie;


             item = new HttpItem()
             {
                 URL = "http://bbs.mydigit.cn/",   
                 Method = "get",   
                 IsToLower = false, 
                 Cookie = cookie,
                 Referer = "",  
                 Postdata = "",  
                 Timeout = 100000,    
                 ReadWriteTimeout = 30000,   
                 UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",   
                 ContentType = "application/x-www-form-urlencoded",
                 Allowautoredirect = true,  

                 ResultType = ResultType.String
             };
             result = http.GetHtml(item);
             html = result.Html;

            //貌似不对头,和直接访问"http://bbs.mydigit.cn/"一样,不包含登陆用户信息

             item = new HttpItem()
             {
                 URL = "http://bbs.mydigit.cn/job.php?action=mutiupload",   
                 Method = "get",   
                 IsToLower = false, 
                 Cookie = cookie,
                 Referer = "",  
                 Postdata = "",//Post数据     可选项GET时不需要写   
                 Timeout = 100000,    
                 ReadWriteTimeout = 30000,   
                 UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",   
                 ContentType = "application/x-www-form-urlencoded",
                 Allowautoredirect = true,  

                 ResultType = ResultType.String
             };
             result = http.GetHtml(item);
            //通过浏览器登陆访问这个地址的时候,返回值是{"uid":"461845","step":2,"verify":"4f2785cb"}
            //而我这里的返回值为{"uid":"","step":2,"verify":"abef30dd"},缺少UID的值,和没登陆一样



        }
    }
}

本帖被以下淘专辑推荐:



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-4-16 23:20:41 | 显示全部楼层
本帖最后由 Monn 于 2014-4-16 23:24 编辑

你那登录的cookie貌似没处理,C#返回的cookie都带的有path:/之类的,有些还有逗号,你需要处理的,不处理直接是登录不上去的。试试用CookieCollection。。如果不行,那只能自己处理cookie了
发表于 2014-4-17 10:48:04 | 显示全部楼层
[C#] 纯文本查看 复制代码
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;
using DotNet4.Utilities;
using System.Net;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            HttpHelper http = new HttpHelper();

            HttpItem item = new HttpItem()
              {
                  URL = "http://bbs.mydigit.cn/login.php",
                  Method = "post",
                  Postdata = "jumpurl=http://bbs.mydigit.cn/&step=2&ajax=1&pwuser=用户名&pwpwd=密码&lgt=0",
                  Timeout = 100000,
                  ReadWriteTimeout = 30000,
                  ContentType = "application/x-www-form-urlencoded",
                  Allowautoredirect = true,
                  ResultCookieType = ResultCookieType.CookieCollection
              };
            HttpResult result = http.GetHtml(item);

            //登陆成功   返回值<?xml version="1.0" encoding="gbk"?><ajax><![CDATA[success	[url]http://bbs.mydigit.cn/[/url]]]></ajax>

            string html = result.Html;
            //这个就是登录之后的Cookie
            CookieCollection cookie = result.CookieCollection;


            //访问主页测试
            item = new HttpItem()
            {
                URL = "http://bbs.mydigit.cn/",
                ResultCookieType = ResultCookieType.CookieCollection,
                CookieCollection = cookie
            };
            result = http.GetHtml(item);
            html = result.Html;
            
        }
    }
}
发表于 2014-4-17 10:50:36 | 显示全部楼层
测试一下应该是可以了。
 楼主| 发表于 2014-4-17 11:01:24 | 显示全部楼层
站长苏飞 发表于 2014-4-17 10:48
[mw_shl_code=csharp,true]using System;
using System.Collections.Generic;
using System.ComponentMod ...

非常感谢站长的热心帮助,感谢
发表于 2014-4-17 14:07:29 | 显示全部楼层
膜拜中……
回复

使用道具 举报

发表于 2015-3-31 13:01:30 | 显示全部楼层
受教了学习中……
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-4-19 19:13

© 2014-2021

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