C++ 模拟用户登录,发送post包

JamOfCode 2011-08-20 05:37:47
如何模拟用户登录并且获取用户登录后的信息??

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

post 包如下:


(Request-Line):POST /toploginnew.asp?action=login HTTP/1.1
Accept:*/*
Referer:http://www.microbell.com/toploginnew.asp
Accept-Language:zh-cn
Content-Type:application/x-www-form-urlencoded
Accept-Encoding:gzip, deflate
User-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.com
Content-Length:56
Connection:Keep-Alive
Cache-Control:no-cache
Cookie: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=



我的登录代码

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;
...全文
3356 34 打赏 收藏 转发到动态 举报
写回复
用AI写文章
34 条回复
切换为时间正序
请发表友善的回复…
发表回复
goudan8484 2013-09-03
  • 打赏
  • 举报
回复
我也遇到了 C++ 发POST登录一个https的网页 同事用C#简单的正常http编程操作就登录成功了 我用C++ 死活登不上 折腾了一个多星期 还是找不到问题所在 与编码有关吗?我做了发送数据和返回的数据的编码 还是不行 没影响 到底咋回事?代码和前面的用http类的差不多
RLib 2013-06-29
  • 打赏
  • 举报
回复
http://blog.csdn.net/rrrfff/article/details/8872540
kuaiei 2013-06-12
  • 打赏
  • 举报
回复
我也遇到问题了
wuzhiwenk3001 2012-05-08
  • 打赏
  • 举报
回复
我也和LZ一样,所有数据都和抓来的一样,但是就不能登录
huangzongwu 2011-09-08
  • 打赏
  • 举报
回复
这个也要看http服务器支持不支持post的,有的只支持send,有的只支持post,有的都支持
ok1234567 2011-09-03
  • 打赏
  • 举报
回复
确认你的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)也属正常
LuciferStar 2011-09-03
  • 打赏
  • 举报
回复
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

maoxing63570 2011-09-03
  • 打赏
  • 举报
回复
用libcurl无压力

#include <cstdio>
#include <curl.h>
#include <cstring>
#include <cstdlib>
#include <types.h>
#include <easy.h>
#pragma comment(lib,"libcurl_imp.lib")
int main()
{
curl_global_init(CURL_GLOBAL_ALL);
CURL *myHandle=curl_easy_init();

curl_easy_setopt(myHandle,CURLOPT_USERAGENT,"Mozilla/4.0");
curl_easy_setopt(myHandle,CURLOPT_AUTOREFERER,1);
curl_easy_setopt(myHandle,CURLOPT_FOLLOWLOCATION,1);
curl_easy_setopt(myHandle,CURLOPT_COOKIEFILE,"");

curl_easy_setopt(myHandle,CURLOPT_URL,"http://www.3322.org/dyndns/login");
curl_easy_perform(myHandle);

char *data="username=xxxxxx&actiong=login&password=xxxxxxxxx&submit=%E7%99%BB%E5%BD%95&action=login";
char *update="hostname=xxxx&myip=192.168.1.1&mx=&backmx=NO&wildcard=OFF&offline=NO&act=mod&modflag=modflag";
curl_easy_setopt(myHandle,CURLOPT_POSTFIELDS,data);
curl_easy_perform(myHandle);
curl_easy_setopt(myHandle,CURLOPT_URL,"http://www.3322.org/dyndns/chrrs");

curl_easy_setopt(myHandle,CURLOPT_POSTFIELDS,update);
curl_easy_perform(myHandle);
curl_easy_cleanup(myHandle);

return 0;
}

之前写了用来更新3322域名的
汪宁宇 2011-09-03
  • 打赏
  • 举报
回复
[Quote=引用 25 楼 jamofcode 的回复:]

引用 24 楼 rrrfff 的回复:
用HttpRequest搞定。


能给个详细的例子吗
[/Quote]

参考之~~

VC POST表单模拟登录新浪邮箱

利用WinInet查询考生信息
JamOfCode 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 24 楼 rrrfff 的回复:]
用HttpRequest搞定。
[/Quote]

能给个详细的例子吗
RLib 2011-08-31
  • 打赏
  • 举报
回复
用HttpRequest搞定。
aCracker 2011-08-25
  • 打赏
  • 举报
回复
我最近也在做。wininet 蛮好用。
JamOfCode 2011-08-24
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 xiaoc1026 的回复:]

这里有我写的发包代码,看看吧

http://download.csdn.net/source/2427268
[/Quote]

我没有那么多下载分啊。。。。。
见习学术士 2011-08-24
  • 打赏
  • 举报
回复
这里有我写的发包代码,看看吧

http://download.csdn.net/source/2427268
cet2 2011-08-24
  • 打赏
  • 举报
回复
还是没有解决啊。
cet2 2011-08-24
  • 打赏
  • 举报
回复
错误很多啊。
vc6下编不过
CString的多个成员函数使用错误

[Quote=引用 20 楼 xiaoc1026 的回复:]
这里有我写的发包代码,看看吧

http://download.csdn.net/source/2427268
[/Quote]
cet2 2011-08-23
  • 打赏
  • 举报
回复
我是模拟一个BBS的用户(已经登录成功了),回复帖子的过程。
组了一个包 然后POST过去。结果不成功。
把提交的数据用"formhash=2d844839&subject=&message=eeeeeeeeeeeeeeeeeeeeeee\n"
形式,附加在POST包的后面,

请指点一下哪里不对?
难道是cookie不行?
zzw820626 2011-08-23
  • 打赏
  • 举报
回复
路过,帮顶
cet2 2011-08-23
  • 打赏
  • 举报
回复
带有hashcode的提交不成功啊。

[Quote=引用 4 楼 wct511 的回复:]
表示用wininet压力不大~ 轻松加愉快实现
[/Quote]
JamOfCode 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 xinshuow 的回复:]

Content-Length:56为什么是56, 这个是"name=wh85125&pwd=wh85125&checkbox=on&tijiao=%B5%C7%C2%BC"的长度么?
[/Quote]
对的
加载更多回复(14)

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧