-
-
-
- #include "stdafx.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "winsock2.h"
- #pragma comment(lib,"ws2_32.lib")
- int main(int argc, char* argv[])
- {
-
- SOCKET hsocket;
- SOCKADDR_IN saServer;
- WSADATA wsadata;
- LPHOSTENT lphostent;
- int nRet;
- char* host_name="www.********.com";
- char* reqHead="POST ********* HTTP/1.1\r\n"
- "Accept: */*\r\n"
- "Referer: http://www.*********\r\n" //这些数据你可以自己抓包获得
- "Accept-Language: zh-CN\r\n"
- "User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN; twchrome)\r\n"
- "Content-Type: application/x-www-form-urlencoded\r\n"
- "Accept-Encoding: gzip, deflate\r\n"
- "Host: www.*******.com\r\n"
- "Content-Length: 375\r\n"
- "Connection: Keep-Alive\r\n"
- "Cache-Control: no-cache\r\n"
- "Cookie: ************** \r\n\r\n"
- "user=test&pass=123";
-
-
- if(WSAStartup(MAKEWORD(2,2),&wsadata))
- printf("初始化SOCKET出错!");
- lphostent=gethostbyname(host_name);
- if(lphostent==NULL)
- printf("lphostent为空!");
- hsocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
- saServer.sin_family = AF_INET;
- saServer.sin_port = htons(80);
- saServer.sin_addr =*((LPIN_ADDR)*lphostent->h_addr_list);
-
- nRet = connect(hsocket,(LPSOCKADDR)&saServer,sizeof(SOCKADDR_IN));
- if(nRet == SOCKET_ERROR)
- {
- printf("建立连接时出错!");
- closesocket(hsocket);
- return0;
- }
-
-
- nRet = send(hsocket,req,strlen(req),0);
- if(nRet==SOCKET_ERROR)
- {
- printf("发送数据包时出错!");
- closesocket(hsocket);
- }
- char Dest[3000];
- nRet=1;
- while(nRet>0)
- {
-
- nRet=recv(hsocket,(LPSTR)Dest,sizeof(Dest),0);
- if(nRet>0)
- Dest[nRet]=0;
- else
- Dest[0]=0;
-
- printf("\nReceived bytes:%d\n",nRet);
- printf("Result:\n%s",Dest);
- }
- }