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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 7872|回复: 2

[HttpHelper] post htpps遇到csrf令牌问题

[复制链接]
发表于 2015-7-4 21:31:45 | 显示全部楼层 |阅读模式
1金钱
我在模拟paypal网登陆时 遇到csrf令牌不匹配问题
请问各位大神 这个该怎么解决?
附上代码。。
[C#] 纯文本查看 复制代码
 HttpHelper http=new HttpHelper();
            HttpItem it = new HttpItem()
            {
                URL = "https://www.paypal.com/signin/?country.x=US&locale.x=en_US#",
                Method = "GET",
                Host = "www.paypal.com",
                UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)",
                Accept = "text/html, application/xhtml+xml, */*"
            };
            it.Header.Add("Accept-Language", "zh-CN");
            it.Header.Add("Accept-Encoding", "gzip, deflate");
            HttpResult resultw = http.GetHtml(it);
            string cookie = resultw.Cookie;
          
            string _csrf = "<input type=\"hidden\" id=\"token\" name=\"_csrf\" value=\"(.*?)\">";
            string n = Regex.Match(resultw.Html, _csrf).Groups[1].Value;
            string bp = "v=1;a1=11~a2=0~a3=17801~a4=Mozilla~a5=Microsoft Internet Explorer~a6=5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)~a7=0~a8=zh-CN~a9=true~a10=x86~a11=true~a12=Win32~a13=zh-CN~a14=Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)~a15=true~a16=zh-CN~a17=gb2312~a18=www.paypal.com~a19=96~a20=96~a21=true~a22=0~a23=1920~a24=1080~a25=24~a26=1040~a27=na~a28=Sat Jul 4 17:37:38 UTC+0800 2015~a29=8~a30=na~a31=yes~a32=x86~a33=yes~a34=no~a35=no~a36=yes~a37=no~a38=online~a39=no~a40=Win32~a41=no~a42=no~";
            string email = "coldsnow@qq.com"; //电子邮箱
            string loginPwd = "CHENZHEN"; //登陆密码
            string str = "?bp_mid=" + bp;
            str += "&flow_name=signin";
            str += "&processSignin=main";
            str += "&_csrf=" + n;
            str += "&login_email=" + email;
            str += "&login_password=" + loginPwd;
            str += "&locale.x=en_US";
          
            HttpItem item = new HttpItem()
            {
                URL =this.webBrowser1.Url.ToString(),
                Method = "POST",
                Host = "www.paypal.com",
                Accept="application/json, text/javascript, */*;q=0.01",
                Encoding =Encoding.GetEncoding("utf-8"),
                Referer = "https://www.paypal.com/signin/",
                ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
                UserAgent ="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)",
                PostEncoding=Encoding.GetEncoding("utf-8"),
                PostDataType=PostDataType.String,
                Postdata=str,
                Cookie="cookie_check=yes; s_pers=%20s_fid%3D5EE95B5F85FDD8B9-3AEAF529BE78BDC2%7C1499171000284%3B%20gpv_c43%3Dmain%253Aunifiedlogin%253A%253A%253Alogin%7C1436014400288%3B%20gpv_events%3Dno%2520value%7C1436014400292%3B; ts=vreXpYrS%3D1530683405%26vteXpYrS%3D1436014428%26vr%3D4f57a7fc14e0a491a40767e7ff16373f%26vt%3D58c6005514e0a4a189b26fc2ffa27cb7; KHcl0EuY7AKSMgfvHl7J5E7hPtK=lOhLpRNKXi_GRPO53HZ6upWmuWdMqrEiZxC6bayI_n4-TrRPxESAQdPxefaorFaJP23xgiiOc6UHjda8; _ga=GA1.2.74119069.1435850492; login_email=ywh80%40163.com; ui_experience=home%3D2%26login_type%3DEMAIL_PASSWORD; X-PP-ADS=AToBxM2XVZhoBfv-SxaFz8.s8.3BJKk; h3AkkNwOxPEPRslUIy3vhqkniPK=1MQj6iPRAu5-vhgNV0zkoRDIAAoSUqOCQ9fjKXzaQ3C_VKRUD5b7X5I58pK; consumer_display=USER_HOMEPAGE%3d2%26USER_TARGETPAGE%3d0%26USER_FILTER_CHOICE%3d0%26BALANCE_MODULE_STATE%3d1%26GIFT_BALANCE_MODULE_STATE%3d1%26LAST_SELECTED_ALIAS_ID%3d0%26SELLING_GROUP%3d1%26PAYMENT_AND_RISK_GROUP%3d1%26SHIPPING_GROUP%3d1%26HOME_VERSION%3d1436099021%26MCE2_ELIGIBILITY%3d4294967295; x-pp-p=ZD8NkV0hwf40jg8zd78fLNZcyyddkAjfMlCX6nFu.lkmpg1KytCw8s1sCybPH0HCujOzd-stFKTnGXjy7iMhtPVep5enL4WkrujQRjlJQOMz.X43ybBeB0bwJpGXJKocg57gsaCPxEGrguXvXLpU2QsQTwbzNKHu7mHKiXHM-J6K2675YUCJwLvjR890dtUPHYa.95-ObgHm-EHCxf7.9Kp4keqLg19RhBSkkRrXoETVm6olKpBNP-e3pE6N-pbJ; navlns=1.0; feel_cookie=a%205%20_home%20b%205%20_home%20c%206%20webscr%20d%206%20webscr%20e%2028%20Customer%2faccount%2fWelcome.xsl%20f%2028%20Customer%2faccount%2fWelcome.xsl%20g%205%20zh_CN%20h%205%20zh_CN%20i%2028%20xpt%2fCustomer%2faccount%2fWelcome%20j%2028%20xpt%2fCustomer%2faccount%2fWelcome%20k%2015%20%e6%88%91%e7%9a%84%e8%b4%9d%e5%ae%9d%20-%20%20l%2015%20%e6%88%91%e7%9a%84%e8%b4%9d%e5%ae%9d%20-%20%20; _gat=1; LANG=en_US%3BUS; X-PP-SILOVER=name%3DLIVE6.WEB.1%26silo_version%3D880%26app%3Dunifiedloginnodeweb%26TIME%3D1389401941; s_sess=%20s_cc%3Dtrue%3B%20s_ppv%3D0%3B%20tr_p1%3Dmain%253Aunifiedlogin%253A%253A%253Alogin%3B%20v31%3Dmain%253Aunifiedlogin%253A%253A%253Alogin%3B%20s_sq%3Dpaypalglobal%253D%252526pid%25253Dmain%2525253Aunifiedlogin%2525253A%2525253A%2525253Alogin%252526pidt%25253D1%252526oid%25253DLogin%252526oidt%25253D3%252526ot%25253DSUBMIT%252526oi%25253D56%3B; HaC80bwXscjqZ7KM6VOxULOB534=WnLDO-D568GwAB8hEIfzFNl1bC1Cb0qOOQe7A3xTY_qJ-7E9dgw5nLolJLemv8O-Yd7LCIqm0GXR8tAmBSEgbW9LP__rM478ywsxi0DP1lNBjywubGFqbjxp8LpMD971fOvNA0; cwrClyrK4LoCV1fydGbAxiNL6iG=U6PUo_9H2Nnb38YKWXdXKErXj2KmdSdqhikbLWxwrD0Rea8palwSCQvQ_oeytRWgIJDVxs8oK57aIdzzYGpoyk13lU1zUVranzTa0gKtqqIXoHB_WUcYm2UJP0Is8HruLYp1KUVyGdc_6kFcbOxdO9oVhRJ6YZqnNUC_NPkvfBNfJYilpSy1iFqXXtdUbKhkT_mEpDB7aXolISWMbcC3NxRbAHN1UWQblweF-4beBIhgFZicaJfVqL0Afk6tidjcNZg-qW; SEGM=488ed238c77c4216ab7e7d1784feab344216ab7e7d1784feab3a4; navcmd=_home-customer; VmyeHxjTc5yWtKApgk8-f2SgjEC=x_AlzjzHfIQQwB0x5-c6QkD12mgupM-EQx4ULw7BtztZqX0wzc_m7Q7qbWhziVVB57k4OlMi6ESyppWzS8dvsRHyzse; x-pp-s=eyJ0IjoiMTQzNjAxMTk3NTI5MiIsIm0iOiIwIn0; tkkUEuFUb_mahcIlS49RY52hwu8=UC-2Q72DMF4oRfTRoOd4up0wKgFOg489q5EzjAN87Y3Rv7Y6tggzGIm4aP0qsff10v_XdibWigPFe3PV1OTOOtUik7B1gewM4b4AHm; Apache=10.16.0.204.1435850211722059; AKDC=slc-b-origin-www-1.paypal.com; nsid=s%3ApegRd6XEkt_TLbNRe1jBjZb_6jJp_qBC.vfi%2FL%2BqyOvD4u4JkPdimCXG6KwEaGe%2BWTuWkWSZJq5w; tcs=main%3Aunifiedlogin%3A%3A%3Alogin%7CbtnLogin"
            };
            item.Header.Add("Accept-Language","zh-CN");
            item.Header.Add("Accept-Encoding","gzip, deflate");
             HttpResult res = http.GetHtml(item);
            richTextBox1.AppendText(res.Html);



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2015-7-4 22:33:19 | 显示全部楼层
代码执行的结果是

":{"msg":"CSRF error: CSRF token mismatch"},"

明显是csrf令牌不匹配额。。。



回复

使用道具 举报

发表于 2015-7-9 21:49:11 | 显示全部楼层
强烈支持楼主ing……
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-11-24 03:25

© 2014-2021

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