首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

C++ 模拟用户登录,发送post包解决方法

2012-01-19 
C++ 模拟用户登录,发送post包如何模拟用户登录并且获取用户登录后的信息??我用抓包工具抓了post的包,写程

C++ 模拟用户登录,发送post包
如何模拟用户登录并且获取用户登录后的信息??

我用抓包工具抓了post的包,写程序发送过去不能得到登录后的页面~~~

post 包如下:

C/C++ code
(Request-Line):POST /toploginnew.asp?action=login HTTP/1.1Accept:*/*Referer:http://www.microbell.com/toploginnew.aspAccept-Language:zh-cnContent-Type:application/x-www-form-urlencodedAccept-Encoding:gzip, deflateUser-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)Host:www.microbell.comContent-Length:56Connection:Keep-AliveCache-Control:no-cacheCookie:Hm_lvt_d554f0f6d738d9e505c72769d450253d=1313830937218; Hm_lpvt_d554f0f6d738d9e505c72769d450253d=1313830937218; c=; cnzz_a1752123=0; sin1752123=; rtime=1; ltime=1313830937031; cnzz_eid=62850849-1313743537-; ASPSESSIONIDAQCDDRBT=IPKOAKFDHBBIAACOHKDIEPPD; MBname=; MBemail=; MBpermission=; MBpwd=


我的登录代码
C/C++ code
string host = GetHost(url);    string urlPath = GetUrlPath(url);    timeval connectTime;    connectTime.tv_sec = 6;    connectTime.tv_usec = 0;    SOCKET sock;    if (!ConnectWebSite(sock, host, connectTime, path))    {        return false;    }    string POST = urlPath;    char header[1024] = {0};        sprintf(header,post的包字节);        send(sock, header, strlen(header), 0);    ReceiveStream(sock, stream, time, path);    closesocket(sock);    WSACleanup();    return true;


[解决办法]
CHttpFile模拟POST方式获取header和HTML数据http://hi.baidu.com/singlestudio/blog/item/9c15e6136ece258b6538dba5.html

CHttpFile模拟GET方式获取header和HTML数据
http://hi.baidu.com/singlestudio/blog/item/fa0340fab95890829e5146c1.html


[解决办法]
确认你的Cookie 是通过登入页面即时获取
有些值在返回头中可以解析,有些值则需要解析脚本,计算出值

header+="Cookie:Hm_lvt_d554f0f6d738d9e505c72769d450253d=1314002159859; dnt=ppp=0&sigstatus=1&pmsound=0&userid=19927&referer=index%2Easpx&invisible=0&password=2J3H3Fjc%2FgJPZw48PGQiGg0Lgk9FKb5Kx2hMJTYpW68TujDn6XqTLg%3D%3D&expires=120&tpp=0; c=; rtime=2; ltime=1314002309859; cnzz_eid=62850849-1313743537-; MBname=; MBemail=; MBpermission=; MBpwd=; ASPSESSIONIDCQDCCRBT=GIBPDEFBIKNPENAKBOBIDOEE\r\n\r\n";

请求发出后,确认其返回状态,而不一定是登入结果页面,有几次的转换(302)也属正常

热点排行