18,356
社区成员
发帖
与我相关
我的任务
分享
POST /vote/rankpost.php HTTP/1.1
Accept: application/msword, application/x-shockwave-flash, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Referer: http://www.ttpaihang.com/vote/rank.php?page=3&voteid=630&sortby=
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)
Host: www.ttpaihang.com
Content-Length: 85
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: cnzz_a2586704=2; sin2586704=; rtime=0; ltime=1297042094562; cnzz_eid=72938296-1297038354-; PHPSESSID=018742a9aca247000b098a4d07dc338e; CookieCheck=OK; 2011-02-07=5779%2C5128%2C5773%2C13447%2C11218%2C6936
choice_id%5B%5D=16205&post_data=%CC%E1%BD%BB%CD%B6%C6%B1&voteid=630&MouX=478&MouY=604
#include "winsock2.h"
#pragma comment(lib,"ws2_32.lib")
int main(int argc, char* argv[])
{
SOCKADDR_IN saServer;
LPHOSTENT lphostent;
WSADATA wsadata;
SOCKET hsocket;
int nRet;
char* host_name="http://www.ttpaihang.com";
char* req=
"POST /vote/rankpost.php HTTP/1.1\r\n"
"Accept: application/msword, application/x-shockwave-flash, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\r\n"
"Referer: http://www.ttpaihang.com/vote/rank.php?page=3&voteid=630&sortby=\r\n"
"Accept-Language: zh-cn\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n"
"Host: www.ttpaihang.com\r\n"
"Content-Length: 85\r\n"
"Connection: Keep-Alive\r\n"
"Cache-Control: no-cache\r\n"
"Cookie: cnzz_a2586704=2; sin2586704=; rtime=0; ltime=1297042094562; cnzz_eid=72938296-1297038354-; PHPSESSID=018742a9aca247000b098a4d07dc338e; CookieCheck=OK; 2011-02-07=5779%2C5128%2C5773%2C13447%2C11218%2C6936\r\n"
"choice_id%5B%5D=16205&post_data=%CC%E1%BD%BB%CD%B6%C6%B1&voteid=630&MouX=478&MouY=604";
// 初始化套接字
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);
// 利用SOCKET连接
printf("利用SOCKET连接\n");
nRet = connect(hsocket,(LPSOCKADDR)&saServer,sizeof(SOCKADDR_IN));
if(nRet == SOCKET_ERROR)
{
printf("建立连接时出错!");
closesocket(hsocket);
return 0;
}
// 利用SOCKET发送
printf("发送\n");
nRet = send(hsocket,req,strlen(req),0);
if(nRet==SOCKET_ERROR)
{
printf("发送数据包时出错!");
closesocket(hsocket);
}
char Dest[3000];
nRet=1;
printf("接收\n");
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);
}
return 0;
}
char* req=
"POST /vote/rankpost.php HTTP/1.1\r\n"
"Accept: application/msword, application/x-shockwave-flash, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\r\n"
"Referer: http://www.ttpaihang.com/vote/rank.php?page=3&voteid=630&sortby=\r\n"
"Accept-Language: zh-cn\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n"
"Host: www.ttpaihang.com\r\n\r\n"
"Content-Length: 85\r\n"
"Connection: Keep-Alive\r\n"
"Cache-Control: no-cache\r\n"
"Cookie: cnzz_a2586704=2; sin2586704=; rtime=0; ltime=1297042094562; cnzz_eid=72938296-1297038354-; PHPSESSID=018742a9aca247000b098a4d07dc338e; CookieCheck=OK; 2011-02-07=5779%2C5128%2C5773%2C13447%2C11218%2C6936\r\n"
"choice_id%5B%5D=16205&post_data=%CC%E1%BD%BB%CD%B6%C6%B1&voteid=630&MouX=478&MouY=604";
void CTPToolDlg::SocketSubmit()
{
CString strPacketText=
"POST /vote/rankpost.php HTTP/1.1\r\n"
"Accept: application/x-shockwave-flash, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n"
"Referer: http://www.ttpaihang.com/vote/top_mv/index.php?page=1&sortby=ps\r\n"
"Accept-Language: zh-cn\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n"
"Host: www.ttpaihang.com\r\n\r\n"
"Content-Length: 84\r\n"
"Connection: Keep-Alive\r\n"
"Cache-Control: no-cache\r\n"
"Cookie: cnzz_a2586704=14; sin2586704=; rtime=0; ltime=1297150225515; cnzz_eid=10471700-1297140387-; PHPSESSID=ae37ddcde6f98303ba7c912e13c5cb45; CookieCheck=OK; netauthor=%CC%EC%CC%EC%CD%F8%CD%F8%D3%D1\r\n"
"\r\n"
"choice_id%5B%5D=16034&post_data=%CC%E1%BD%BB%CD%B6%C6%B1&voteid=43&MouX=599&MouY=187";
if(m_socket.Send(strPacketText,strPacketText.GetLength(),0) == SOCKET_ERROR)
{
int err = m_socket.GetLastError();
::MessageBox(AfxGetMainWnd()->m_hWnd,"发送数据时出错","错误",MB_OK);
m_socket.Close();
return;
}
char Dest[3000];
int nRet=1;
CString str;
int err = GetLastError();
while(nRet>0)
{
nRet = m_socket.Receive(Dest,3000,0);
if(nRet>0)
Dest[nRet]=0;
else
Dest[0]=0;
str+=Dest;
}
UpdateData();
m_edit = str;
UpdateData(false);
}