- #include <afxinet.h> // 包含相关的头文件
-
-
- 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"));
- 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();
- }
http://blog.csdn.net/visualeleven/article/details/6656224
模拟登陆115网盘(MFC版)
原文:http://www.cnblogs.com/findumars/p/6006048.html