C++实现申请帐号---发送post提交表单信息包
测试网址为:http://www.exam8.com/
测试网址ip:222.73.24.32
测试帐号:lzh_5
密码:123456789
首先要确定提交表单的信息,我用抓包工具抓了post的包,然后写程序模拟发送过程,实现了登录过程。
注意事项:
1.一定要按照抓包的信息发送,甚至空格、换行数都要一样;
2.模拟登录的网页没有验证码;
代码:
//post提交表单申请帐号 #include<stdio.h> #include<string> #include<winsock2.h> #include<windows.h> #include<iostream> #include<fstream> #pragma comment(lib, "ws2_32.lib") #define max 20480 using namespace std; int main() { int num,sum; SOCKET s; WSADATA wsa; struct sockaddr_in serv; char sndBuf[max], rcvBuf[max]; WSAStartup(MAKEWORD(2, 1), &wsa); if ((s = socket(AF_INET, SOCK_STREAM, 0))<0) { perror("socket error!"); exit(1); } memset(&serv,0,sizeof(serv)); serv.sin_family = AF_INET; serv.sin_port = htons(80); //serv.sin_addr.s_addr = *((int*)*host_addr->h_addr_list); serv.sin_addr.S_un.S_addr = inet_addr("222.73.24.32"); if ((connect(s, (struct sockaddr *)&serv, sizeof(serv)))<0) { perror("connet error!"); exit(1); } memset(sndBuf, 0, max); memset(rcvBuf, 0, max); //头信息 strcat(sndBuf, "POST "); strcat(sndBuf, "/inc/Check.asp HTTP/1.1\r\n"); strcat(sndBuf, "x-requested-with: XMLHttpRequest\r\n"); strcat(sndBuf, "Accept-Language: zh-cn\r\n"); strcat(sndBuf, "Referer: http://reg.exam8.com/"); strcat(sndBuf, "\r\n"); strcat(sndBuf, "Accept: */*\r\n"); strcat(sndBuf, "Content-Type: application/x-www-form-urlencoded\r\n"); strcat(sndBuf, "Accept-Encoding: gzip, deflate\r\n"); strcat(sndBuf, "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; eSobiSubscriber 1.0.0.40; MAAR; .NET4.0C; .NET4.0E; Maxthon/3.0)\r\n"); strcat(sndBuf, "Host: reg.exam8.com\r\n"); strcat(sndBuf, "Content-Length: 149\r\n"); strcat(sndBuf, "Connection: Keep-Alive\r\n"); strcat(sndBuf, "Cache-Control: no-cache\r\n"); strcat(sndBuf, "Cookie: referrer=http%3A//www.baidu.com/s%3Fwd%3D%25e8%2580%2583%25e8%25af%2595%25e5%2590%25a7%26rsv_spt%3D1%26issp%3D1%26f%3D3%26rsv_bp%3D0%26rsv_idx%3D2%26ie%3Dutf-8%26tn%3Dmaxthon2%26rsv_sug3%3D3%26rsv_sug4%3D126%26rsv_sug1%3D1%26oq%3Dkaoshi%26rsp%3D0%26rsv_sug5%3D0; Hm_lvt_80e97646f045b0632f81239c03c83492=1415795254,1415797440,1415889057; ASPSESSIONIDAAQSATDS=LHOBCKMCKEKNEBEHLLHMPHAB\r\n"); strcat(sndBuf, "\r\n"); strcat(sndBuf, "ComeUrl=http%3A//\r\n"); strcat(sndBuf, "user.exam8.com&RegUserName=lzh_5&RegUserPassword=123456789&RegPwdConfirm=123456789&RegEmail=[email protected]&checkbox1=&Action=reg"); puts(sndBuf); if ((num = send(s,sndBuf,max, 0))<0) { perror("send error!"); exit(1); } puts("send success!\n"); sum = recv(s, rcvBuf, max-1, 0);//如果rcvBuf的存储空间减小,则分几次copy if(sum>0) { puts("OK!"); printf("%s",rcvBuf); } puts("\nread success!\n"); closesocket(s); system("pause"); WSACleanup(); return 0; }
运行结果:
1.提交给网站的表单信息
2.网页的返回信息
3.申请成功后返回信息
4.在此运行此程序返回信息
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。