如何模拟用户登录并且获取用户登录后的信息??我用抓包工具抓了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;
(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;
POST /toploginnew.asp?action=login HTTP/1.1
这个每一行的后面都要有\r\n最后
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=
后面是\r\n\r\n
但遇到好几个问题1、我是向论坛的一个表单中,自动提交内容(此时已经登录进去了),但在发送POST内容是,怎么把提交的发言内容带进去呢?2、发送过去之后,一直不成功。不知道为什么
{
CString strFormData = "username=abc&password=123"; // 需要提交的数据
CInternetSession session;
CHttpFile* pHttpFile = NULL;
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded"); // 请求头
try
{
pHttpFile=(CHttpFile*)session.OpenURL(sHttpName);//打开文件
}
catch(...)
{
//throw;
}
CString sSentence = "";
if(pHttpFile)
{
DWORD dwStatus;
DWORD dwBuffLen = sizeof(dwStatus);
BOOL bSuccess = pHttpFile->QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwBuffLen);
if( bSuccess && dwStatus>= 200 &&dwStatus<300 ) // status codes:200-299 Success
{
BOOL result = pHttpFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
while(pHttpFile->ReadString(sSentence)) // 读取提交数据后的返回结果
{
strGetSentence = strGetSentence + sSentence + char(13) + char(10);
}
}
pHttpFile->Close();
delete pHttpFile;
}
session.Close();
}
能给我一个SDK的版本吗??
"POST /toploginnew.asp?action=login HTTP/1.1\r\n"\
"Accept: */*\r\n"\
"Referer: http://www.microbell.com/toploginnew.asp\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; .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)\r\n"\
"Host: www.microbell.com\r\n"\
"Content-Length: 56\r\n"\
"Connection: Close\r\n"\
"Cache-Control: no-cache\r\n\r\n"\
"name=wh85125&pwd=wh85125&checkbox=on&tijiao=%B5%C7%C2%BC"
这样好像也不行~~~~我想能不能构造一个post的请求包过去就行了,不想用MFC的东西~~~~
这个版本只能在MFC的project里面用吧,而且拿下来的字节流是乱码
sprintf(header, "POST /toploginnew.asp?action=login HTTP/1.1\r\n"\
"Accept: */*\r\n"\
"Referer: http://www.microbell.com/toploginnew.asp\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; .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)\r\n"\
"Host: www.microbell.com\r\n"\
"Content-Length: 56\r\n"\
"Connection: Close\r\n"\
"Cache-Control: no-cache\r\n\r\n"\
"name=wh85125&pwd=wh85125&checkbox=on&tijiao=%B5%C7%C2%BC");
这样也是返回空串, 我三次握手已经成功了get方式可以返回网页~~~~~
strcat(header, "GET ");
strcat(header, GET.c_str());
strcat(header, " HTTP/1.1\r\n");
strcat(header, "HOST: ");
strcat(header, host.c_str());
strcat(header, "\r\nConnection: Close\r\n\r\n");求解释~~~~~~~~~~~~~~~~~
组了一个包 然后POST过去。结果不成功。
把提交的数据用"formhash=2d844839&subject=&message=eeeeeeeeeeeeeeeeeeeeeee\n"
形式,附加在POST包的后面,请指点一下哪里不对?
难道是cookie不行?
用wininet,最后在httpsendrequest老是false;string header = "POST /toploginnew.asp?action=login HTTP/1.1\r\n";
header+="Accept:*/*\r\n";
header+="Referer:http://www.microbell.com/toploginnew.asp\r\n";
header+="Accept-Language:zh-cn\r\n";
header+="Content-Type:application/x-www-form-urlencoded\r\n";
header+="Accept-Encoding:gzip, deflate\r\n";
header+="User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .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)\r\n";
header+="Host:www.microbell.com\r\n";
header+="Content-Length:56\r\n";
header+="Connection:Keep-Alive\r\n";
header+="Cache-Control:no-cache\r\n";
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";
string option = "name=wh85125&pwd=wh85125&checkbox=on&tijiao=%B5%C7%C2%BC"; bool flag = HttpSendRequest(hOpenRequest, header.c_str(), header.length(), (LPVOID)option.c_str(), option.length());
我快崩溃了。。为什么post包老是发送失败, 我是严格按照包格式构造的,之前的所有句柄是正确的~~~
HINTERNET hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!hInternet)
{
return -1;
}
HINTERNET hInternetConnect = InternetConnect(hInternet, TEXT("http://www.microbell.com/"),
INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,INTERNET_SERVICE_HTTP, 0, 0);
if (!hInternetConnect)
{
return -1;
} string ss = "*/*";
const char *p = ss.c_str(); HINTERNET hOpenRequest = HttpOpenRequest(hInternetConnect,
"POST",
"/toploginnew.asp?action=login",
HTTP_VERSION,
"http://www.microbell.com/toploginnew.asp",
&p,
INTERNET_FLAG_KEEP_CONNECTION,
0); if (!hOpenRequest)
{
return -1;
} string header = "POST /toploginnew.asp?action=login HTTP/1.1\r\n";
header+="Accept:*/*\r\n";
header+="Referer:http://www.microbell.com/toploginnew.asp\r\n";
header+="Accept-Language:zh-cn\r\n";
header+="Content-Type:application/x-www-form-urlencoded\r\n";
header+="Accept-Encoding:gzip, deflate\r\n";
header+="User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .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)\r\n";
header+="Host:www.microbell.com\r\n";
header+="Content-Length:56\r\n";
header+="Connection:Keep-Alive\r\n";
header+="Cache-Control:no-cache\r\n";
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";
header+="name=wh85125&pwd=wh85125&checkbox=on&tijiao=%B5%C7%C2%BC\r\n\r\n";
string option = "name=wh85125&pwd=wh85125&checkbox=on&tijiao=%B5%C7%C2%BC";
bool flag = HttpSendRequest(hOpenRequest, NULL, 0, (LPVOID)option.c_str(), option.length());
int result = GetLastError();
这是用wininet实现的,但是现在GetLastError返回12007,也就是servername不能解析。不知道哪里参数设的不对。
vc6下编不过
CString的多个成员函数使用错误
参考之~~VC POST表单模拟登录新浪邮箱利用WinInet查询考生信息
#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域名的
http://hi.baidu.com/singlestudio/blog/item/fa0340fab95890829e5146c1.html
有些值在返回头中可以解析,有些值则需要解析脚本,计算出值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)也属正常