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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 70376|回复: 16

[例子] C#Httphelper登录小米账户(https://account.xiaomi.com/pass/serviceLogin)源码

 关闭 [复制链接]
发表于 2014-1-13 11:33:26 | 显示全部楼层 |阅读模式
[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 DotNet.Utilities;
using System.Text.RegularExpressions;

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

        private void button1_Click(object sender, EventArgs e)
        {
            string username =textBox1.Text.Trim();// 
            string password =textBox2.Text.Trim();
            string Cookies = "";// 
            HttpItem itemSign = new HttpItem()          //获取_sign
            {
                URL = "https://account.xiaomi.com/pass/serviceLogin",
            };
            HttpHelper http = new HttpHelper();
            HttpResult httpresult = http.GetHtml(itemSign);
            Cookies = httpresult.Cookie;
          string FrameSrc = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=var iframeSrc = \").*\"").Value.ToString().Replace("\"", ""));
            HttpItem item = new HttpItem()         //登陆Post
            {
                URL = "https://account.xiaomi.com/pass/serviceLoginAuth2",
                Method = "POST",
                Referer = "https://account.xiaomi.com/pass/serviceLogin",
                ContentType = "application/x-www-form-urlencoded",
                Postdata = string.Format("passToken={0}&user={1}&pwd={2}&callback={3}&sid={4}&qs={5}&hidden={6}&_sign={7}", "", username, password, CallBack, SID, QS, HIDDEN, SIGN)
            };
            HttpResult result = http.GetHtml(item);
          richTextBox1.Text = result.Html;
        }
    }
}

想要源码的可以到我的商店购买http://www.sufeinet.com/thread-8276-1-1.html


这个能正常登录小米账户
并获取Cookie值。
大家可以直接拿去用,
这是在解决这个问题
http://www.sufeinet.com/thread-7582-1-1.html
时写的,我贴出来是方便大家使用


本帖被以下淘专辑推荐:



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2014-1-13 20:33:27 | 显示全部楼层
ai_yei 发表于 2014-1-13 20:30
我们学校都没教过。改天去百度看看视频才行,呵呵。

去学习一下吧,这个很有必要。
发表于 2014-1-13 20:24:57 | 显示全部楼层
string CallBack = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=callback = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
            string SID = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=sid = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
            string QS = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=qs = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
            string SIGN = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=sign = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
            string HIDDEN = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=hidden = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
            string FrameSrc = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=var iframeSrc = \").*\"").Value.ToString().Replace("\"", ""));这里面的Regex.Match是什么啊?前辈
 楼主| 发表于 2014-1-13 20:26:49 | 显示全部楼层
执行正则表达方式用的,可以百度一下,有空了学习一下正则,这是开发必备
发表于 2014-1-13 20:30:55 | 显示全部楼层
我们学校都没教过。改天去百度看看视频才行,呵呵。
发表于 2014-1-13 20:38:36 | 显示全部楼层
什么情况?

发表于 2014-1-13 20:46:04 | 显示全部楼层
301 Moved Permanently
The requested resource has been assigned a new permanent URI.


--------------------------------------------------------------------------------
Powered by Tengine/1.5.2


301永久移动
所请求的资源已被分配了一个新的永久性的URI。


-------------------------------------------------- ------------------------------
本站由Tengine/1.5.2
这是为什么啊?
发表于 2014-1-14 10:11:52 | 显示全部楼层
我大致看了下~这个301 301 还是客户端跳转,服务器端跳转貌似是不会在头信息里面给出相应的信息的。客户端跳转分为 js代码跳转、还有写在头信息里面location跳转(让浏览器自己跳转)。这两都属于客户端跳转!(理解对否?)
开发工具里面是否跳转(checkbox)是解决这两类问题的?(开发工具把最终的html cookie status header 显示出来,中间跳转过程的信息不予以显示?)还是只解决状态码的跳转问题,js跳转要自己手工分析解决?

发表于 2014-1-14 10:14:06 | 显示全部楼层
苏飞哥 解决的那个问题,是因为问题楼主 没有按请求流程发送相应请求所产生的(最后cookie结果不对,无法后续访问!)如果以后写请求代码严格按照把抓包器里面的html/text这类请求发送给服务器,一般不会出现问题吧?
 楼主| 发表于 2014-1-14 10:16:32 | 显示全部楼层
无法浏览网页 发表于 2014-1-14 10:14
苏飞哥 解决的那个问题,是因为问题楼主 没有按请求流程发送相应请求所产生的(最后cookie结果不对,无法后 ...

一般不会,不过Http请求得具体情况 具体分析,谁也说不好
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-4-25 07:48

© 2014-2021

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