// 模拟登陆115网盘 #include <afxinet.h> // 包括相关的头文件 /* 用抓包工具抓包可得到须要提交的数据,然后模拟提交就可以。 *(有的时候须要得到cookie信息,你能够使用CInternetSession::GetCookie()函数得到该cookie信息)*/
try { #define MAX_COUNT 1024 CInternetSession session(_T("session")); INTERNET_PORT nPort = 80; CHttpConnection* pHttpConnect = session.GetHttpConnection(_T("passport.115.com"), nPort); if(pHttpConnect) { CHttpFile* pFile = pHttpConnect->OpenRequest(CHttpConnection::HTTP_VERB_POST, _T("/?ac=login")); if(pFile) { // 这里是请求头信息,由抓包工具得到该信息 pFile->AddRequestHeaders(_T("POST /?ac=login HTTP/1.1")); pFile->AddRequestHeaders(_T("Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*")); pFile->AddRequestHeaders(_T("Referer: http://passport.115.com/?ac=login&goto=http%3A%2F%2Fu.115.com%2F%3Fac%3Dmy")); pFile->AddRequestHeaders(_T("Accept-Language: zh-cn")); pFile->AddRequestHeaders(_T("User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; EasyBits GO v1.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)")); pFile->AddRequestHeaders(_T("Content-Type: application/x-www-form-urlencoded")); pFile->AddRequestHeaders(_T("Accept-Encoding: gzip, deflate")); pFile->AddRequestHeaders(_T("Host: passport.115.com")); pFile->AddRequestHeaders(_T("Connection: Keep-Alive")); pFile->AddRequestHeaders(_T("Cache-Control: no-cache")); // 这里是要提交的数据。说明一下: xxxx@xx.xxx指的是登陆的邮箱的地址,后面的XXXXXXX表示的是登陆的password,使用的时候换成你自己的就可以 TCHAR szRequest[MAX_COUNT] = _T("login%5Baccount%5D=xxxx@xx.xxx&login%5Bpasswd%5D=XXXXXXX&goto=http%3A%2F%2Fu.115.com%2F%3Fac%3Dmy"); pFile->SendRequest(NULL, 0, szRequest, _tcslen(szRequest)+1); CString strStatus(_T("")); if(pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strStatus)) { AfxMessageBox(strStatus); } pFile->Close(); delete pFile; pFile = NULL; } } pHttpConnect->Close(); delete pHttpConnect; pHttpConnect =NULL; session.Close(); } catch (CInternetException* e) { e->ReportError(); e->Delete(); }