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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 8950|回复: 4

[求助] 再次求助工行贵金属行情获取的问题

[复制链接]
发表于 2013-8-14 09:22:36 | 显示全部楼层 |阅读模式
本帖最后由 leenkon 于 2013-8-14 09:24 编辑

昨天升级了最新的HttpHelper,增加了KeepAlive属性,可以取得cookie了,根据网银抓包,只发送了cookie,但是post过去返回错误代码,应该是系统检测了什么地方木有通过。望高手帮忙!附上我写的测试代码:
  1.     void Button1Click(object sender, EventArgs e)
  2.     {
  3.       HttpHelper HttpHelper = new HttpHelper();
  4.       HttpItem HttpItem=new HttpItem(){
  5.         CerPath= "D:\\11.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数
  6.         URL="https://mybank.icbc.com.cn/icbc/perbank/index.jsp",
  7.         Accept="text/html, application/xhtml+xml, */*",
  8.         ContentType="application/x-www-form-urlencoded",
  9.         Referer="https://mybank.icbc.com.cn",
  10.         Method="GET",
  11.         KeepAlive=true,
  12.       };
  13.       HttpResult Result = HttpHelper.GetHtml(HttpItem);
  14.       string Cookies=Result.Cookie.Replace("; Path=/","");
  15.       string sessionID=Cookies.Substring(15,23);
  16.       COOK=Result.CookieCollection;
  17.       MessageBox.Show(Cookies+"\n"+sessionID);
  18.       
  19.       HttpItem=new HttpItem(){
  20.         CerPath= "D:\\11.cer",
  21.         URL="https://mybank.icbc.com.cn/servlet/AsynGetDataServlet",
  22.         Accept="application/json, text/javascript, */*; q=0.01",
  23.         ContentType="application/x-www-form-urlencoded; charset=UTF-8",
  24.         Referer="https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet",
  25.         UserAgent="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0) LBBROWSER",
  26.         Method="POST",
  27.         Postdata="step=3&area_code=4402&SessionId="+sessionID+"&tranCode=A00033",
  28.         //Postdata="dse_sessionId="+sessionID+"&dse_applicationId=-1&dse_operationName=per_GoldQueryPriceOp&dse_pageId=30&step=1&goldType=rmb_903&kType=realtime&pageType=small&curtype=903&acflag=1&area_code=2312&submitFlag=0",
  29.         Allowautoredirect=true,
  30.         KeepAlive=true,
  31.         CookieCollection=COOK,
  32.         //Cookie=Result.Cookie,
  33.       };
  34.       //HttpItem.CookieCollection=COOK;
  35.       HttpItem.Header.Add("x-requested-with","XMLHttpRequest");
  36.       HttpItem.Header.Add("Cache-Control","no-cache");
  37.       HttpItem.Header.Add("DNT","1");
  38.       Result = HttpHelper.GetHtml(HttpItem);
  39.       string str=Result.Html;
  40.       MessageBox.Show(str+Result.Cookie);
  41.     }
复制代码
请求标头:

请求标头

请求标头

Post数据:

post数据

post数据

发送的Cookie:

发送的cookie

发送的cookie

返回的结果:

得到的结果

得到的结果


工程下载地址: MMTool.rar (51.48 KB, 下载次数: 228)


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-8-14 09:31:10 | 显示全部楼层
   Allowautoredirect=true,不需要设置试试,设置为False
 楼主| 发表于 2013-8-14 09:55:32 | 显示全部楼层
yangying 发表于 2013-8-14 09:31
Allowautoredirect=true,不需要设置试试,设置为False

设置不自动跳转依然是得到的错误代码。。。不知道是不是cookie木有正确传过去?
发表于 2013-8-14 10:00:45 | 显示全部楼层
使用Cookie直接传不要使用CookieCollection
而且你看你处理、Cookie的方法有问题,
你可以选择用我的类来处理这个类在HttpHelper下载的地方有。
你打印出来你的Cookie值自己看看对不对,或者是调试一下看看传的Cookie值,还有你的Sessionid看看对吗?
 楼主| 发表于 2013-8-14 10:12:46 | 显示全部楼层
站长苏飞 发表于 2013-8-14 10:00
使用Cookie直接传不要使用CookieCollection
而且你看你处理、Cookie的方法有问题,
你可以选择用我的类来 ...

谢谢老大,我在看看有问题再来

Sessionid是cookie的一部分,我对比过 是木有问题的
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-5-2 09:42

© 2014-2021

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