通过httpwatch抓包获取qq空间cookies,然后向服务器请求好友,现在只能获取响应头是什么情况啊,大神有请,新人请多多关照!

深耕细作运营人 2015-04-23 12:05:19

#include<stdio.h>
#include<string>
#include<winsock2.h>
#include<windows.h>
#include<iostream>
#include<fstream>

#pragma comment(lib, "ws2_32.lib")

#define maxlengh 6120
using namespace std;

//获取包头
char* GetHeader()
{
char header[4096]={0};
strcat(header,"GET /p/r/cgi-bin/tfriend/friend_show_qqfriends.cgi?uin=212885830&follow_flag=0&groupface_flag=0&fupdate=1&g_tk=1044875203 HTTP/1.1\r\n");
strcat(header,"Accept: */*\r\n");
strcat(header,"X-HttpWatch-RID: 35612-10098\r\n");
strcat(header,"X-Real-Url: X-Real-Url: http://r.qzone.qq.com/cgi-bin/tfriend/friend_show_qqfriends.cgi?uin=212885830&follow_flag=0&groupface_flag=0&fupdate=1&g_tk=1044875203\r\n");
strcat(header,"Referer: http://user.qzone.qq.com/212885830/profile/permit\r\n");
strcat(header,"Accept-Language: zh-CN\r\n");
strcat(header,"Accept-Encoding: gzip, deflate\r\n");
strcat(header,"User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)\r\n");
strcat(header,"Host: user.qzone.qq.com\r\n");
strcat(header,"If-None-Match: \"3746448173\"\r\n");
strcat(header,"DNT: 1\r\n");
strcat(header,"Connection: Keep-Alive\r\n");
strcat(header,"Cookie: QZ_FE_WEBP_SUPPORT=0; cpu_performance_v8=8; __Q_w_s__appDataSeed=1; __Q_w_s_hat_seed=1; __Q_w_s__QZN_TodoMsgCnt=1; Loading=Yes; blabla=dynamic; p_skey=s*ujdFSJsmkBrrW*j5Cl4DD5yteh8fTq1o49bCpWPY0_; pt4_token=zdKJmHVCFWtFnZmWb7Am6Q__; qz_screen=1366x768; pgv_pvid=7870597372; pt2gguin=o0212885830; ptcz=054ca954c0db8da4255226d229fae7c9664713e6535dafc9dffefd87ec591025; o_cookie=319411172; _gscu_661903259=29166055swjoqp19; RK=daFCyIbdcf; uin_cookie=212885830; euin_cookie=9BA8D13C6FCE33C90EDD7EF06DFB051EF4FE81595550C0E0; uin=o0212885830; skey=@0EPfAFxEO; ptisp=cnc; qzone_check=212885830_1429696340; pgv_info=ssid=s7443426740\r\n\r\n");

return header;
}


int main()
{
int num,sum=1;

SOCKET s;
WSADATA wsa;


char sndBuf[maxlengh], rcvBuf[maxlengh];

WSAStartup(MAKEWORD(2, 1), &wsa);

if ((s = socket(AF_INET, SOCK_STREAM, 0))<0)
{
perror("socket error!");
exit(1);
}
int value=5000;
setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char*)&value, sizeof(value));
setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char*)&value, sizeof(value));

struct sockaddr_in serv;
memset(&serv,0,sizeof(serv));
serv.sin_family = AF_INET;
serv.sin_port = htons(80);
serv.sin_addr.S_un.S_addr = inet_addr("112.90.77.143");//httpwatch流上面有写地址和端口//1424 字节 发送到 14.17.42.24:80

if ((connect(s, (struct sockaddr *)&serv, sizeof(serv)))<0)
{
perror("connet error!");
exit(1);
}

memset(sndBuf, 0, maxlengh);
memset(rcvBuf, 0, maxlengh);

//头信息
strcpy(sndBuf,GetHeader());
cout<<sndBuf<<endl;
if ((num = send(s,sndBuf,strlen(sndBuf), 0))<0)
{
perror("send error!");
exit(1);
}

puts("send success!");

string strGet;
int nReadLen=1;
while (nReadLen>0)
{
nReadLen = recv(s, rcvBuf,maxlengh-1, 0);
if (nReadLen<maxlengh-1&&nReadLen!=0)
{
*(rcvBuf+nReadLen)='\0';
}
strGet+=rcvBuf;
memset(rcvBuf, 0, maxlengh);
}

cout<<strGet<<endl;
printf("read success!");

closesocket(s);
system("pause");
WSACleanup();

return 0;

}
...全文
2060 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
翅膀又硬了 2015-04-23
  • 打赏
  • 举报
回复
会不会中间有个'\0'把你的string截断啦?我瞎猜的啊 你看看接收到多少字节。然后加断点看看
  • 打赏
  • 举报
回复
各位大神,帮小弟看看,分析一下哪里出问题了啊。实在奇怪,本来想写个模拟登录微信的也是遇到这个情况,实在不知道该怎么办了。
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
引用 11 楼 zhao4zhong1 的回复:
引用 6 楼 zhuimengchizixinLUN 的回复:
[quote=引用 4 楼 zhao4zhong1 的回复:] 建议楼主学会使用抓包软件比如wireshark
httpwatch不是一样的吗,他们有什么差别吗?
wireshark比httpwatch更底层,我臆测。 [/quote]谢谢耐心回答,折腾到现在还是没有搞好 哈哈下午继续。
  • 打赏
  • 举报
回复
引用 10 楼 nishuodeqianshou 的回复:
明明有封装好的函数你不用,干嘛要自己写呢?
应该用封装好的哪个类啊,初学网络编程时间不长,所以不清楚啊。大神 ,可以帮忙调试一下吗,解决了报酬帮你冲50元的csnd币啊,虽然不多,聊表心意啊
赵4老师 2015-04-23
  • 打赏
  • 举报
回复
引用 6 楼 zhuimengchizixinLUN 的回复:
引用 4 楼 zhao4zhong1 的回复:
建议楼主学会使用抓包软件比如wireshark
httpwatch不是一样的吗,他们有什么差别吗?
wireshark比httpwatch更底层,我臆测。
  • 打赏
  • 举报
回复
明明有封装好的函数你不用,干嘛要自己写呢?
  • 打赏
  • 举报
回复
引用 8 楼 nishuodeqianshou 的回复:
貌似也只能比对包了吧。一定是什么地方跟正确包不同的地方、
求帮我测试一下啊,控制台程序,搞了1天多了,问题解决不了真是让人着急啊
  • 打赏
  • 举报
回复
貌似也只能比对包了吧。一定是什么地方跟正确包不同的地方、
  • 打赏
  • 举报
回复

截图方便各位查看。
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
建议楼主学会使用抓包软件比如wireshark
httpwatch不是一样的吗,他们有什么差别吗?
  • 打赏
  • 举报
回复
引用 3 楼 fly_dragon_fly 的回复:
不确定响应什么,不是返回200的响应了吗,你希望得到什么
我需要得到数据包啊,好友数据包,但是一直只有响应头。
赵4老师 2015-04-23
  • 打赏
  • 举报
回复
建议楼主学会使用抓包软件比如wireshark
fly_dragon_fly 2015-04-23
  • 打赏
  • 举报
回复
不确定响应什么,不是返回200的响应了吗,你希望得到什么
  • 打赏
  • 举报
回复
引用 14 楼 yunchao630 的回复:
会不会中间有个'\0'把你的string截断啦?我瞎猜的啊 你看看接收到多少字节。然后加断点看看
不是这样的,已经解决了,是中间要去掉一个gzip那个。结贴啦

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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