求高人指点CHttpFile怎么用? 本帖最后由 VisualEleven 于 2012-05-14 20:06:44 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用抓包工具抓个包,然后模拟提交数据即可。http://blog.csdn.net/visualeleven/article/details/6656224 Thanks不过还有一个疑问,我自动登陆后,怎么用CHtmlView打开网页呢? 貌似不行啊代码如下: DWORD dwServiceType; CString strServer,strObject; unsigned short nPort;//AFX_INET_SERVICE_HTTP if(!AfxParseURL(_T("http://172.7.18.100:9000"), dwServiceType, strServer, strObject, nPort)) { return false; } CInternetSession sess;//Create session CHttpFile* pFile; ////////////////////////////////////////////// CHttpConnection *pServer = sess.GetHttpConnection(strServer, nPort); if(pServer == NULL) { //strDescript = "对不起,连接服务器失败!"; return false; } pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strObject,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT); if(pFile == NULL) { //strDescript = "找不到网络地址" ; return false; } pFile->AddRequestHeaders(_T("POST /login!login.action?iType=2 HTTP/1.1")); pFile->AddRequestHeaders(_T("Accept: text/html, application/xhtml+xml, */*")); pFile->AddRequestHeaders(_T("Referer: http://172.7.18.100:9000/")); pFile->AddRequestHeaders(_T("Accept-Language: zh-cn")); pFile->AddRequestHeaders(_T("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)")); pFile->AddRequestHeaders(_T("Content-Type: application/x-www-form-urlencoded")); pFile->AddRequestHeaders(_T("Accept-Encoding: gzip, deflate")); pFile->AddRequestHeaders(_T("Host: 172.7.18.100:9000")); pFile->AddRequestHeaders(_T("Connection: Keep-Alive")); pFile->AddRequestHeaders(_T("Cache-Control: no-cache")); // 这里是要提交的数据 TCHAR szRequest[256] = _T("checkFlag=&cmsUrl=http%3A%2F%2F172.7.18.100%3A9000%2F&name=admin&pwd=12345&LoginType=2&LoginText=%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0"); pFile->SendRequest(NULL, 0, szRequest, _tcslen(szRequest)+1); CString strStatus(_T("")); if(pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strStatus)) { AfxMessageBox(strStatus); } m_htmlCtrl.CreateFromStatic(IDC_HTMLVIEW,this); m_htmlCtrl.Navigate(_T("http://172.7.18.100:9000/index!WCIndex.action"));还是到了登陆的界面!http抓包如下:键 值请求 POST /login!login.action?iType=2 HTTP/1.1Accept text/html, application/xhtml+xml, */*Referer http://172.7.18.100:9000/Accept-Language zh-CNUser-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)Content-Type application/x-www-form-urlencodedAccept-Encoding gzip, deflateHost 172.7.18.100:9000Content-Length 133Connection Keep-AliveCache-Control no-cacheCookie JSESSIONID=7351FE0358E560AA09BE6C9EC9E62BFF; username=admin; iType=2请求正文:checkFlag=&cmsUrl=http%3A%2F%2F172.7.18.100%3A9000%2F&name=admin&pwd=12345&LoginType=2&LoginText=%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0 mfc如何将编辑框中的值通过按键在列表框中输出 手动重绘窗口 如何欺骗本地的dns请求信息 #import dll 的问题 vb中用金山词霸提供的dll取词的例子,麻烦高手给翻译成vc++的,关键是... 为什么当调用完dll里面的函数时会错。 截获鼠标,键盘的消息 我在WIN98中用CreateProcess重定向到管道的控制台文本无法获得? 如何限制edit中的输入的数字? 我有一个指向自定义类的指针,无法delete掉,为什么? 悬赏啦!!关于汉信码,谢谢 SetTimer()+OnTimer()+数据库查询代码
http://blog.csdn.net/visualeleven/article/details/6656224
不过还有一个疑问,我自动登陆后,怎么用CHtmlView打开网页呢?
代码如下: DWORD dwServiceType;
CString strServer,strObject;
unsigned short nPort;//AFX_INET_SERVICE_HTTP
if(!AfxParseURL(_T("http://172.7.18.100:9000"), dwServiceType, strServer, strObject, nPort))
{
return false;
}
CInternetSession sess;//Create session CHttpFile* pFile;
//////////////////////////////////////////////
CHttpConnection *pServer = sess.GetHttpConnection(strServer, nPort);
if(pServer == NULL)
{
//strDescript = "对不起,连接服务器失败!";
return false;
}
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strObject,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
if(pFile == NULL)
{
//strDescript = "找不到网络地址" ;
return false;
}
pFile->AddRequestHeaders(_T("POST /login!login.action?iType=2 HTTP/1.1"));
pFile->AddRequestHeaders(_T("Accept: text/html, application/xhtml+xml, */*"));
pFile->AddRequestHeaders(_T("Referer: http://172.7.18.100:9000/"));
pFile->AddRequestHeaders(_T("Accept-Language: zh-cn"));
pFile->AddRequestHeaders(_T("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"));
pFile->AddRequestHeaders(_T("Content-Type: application/x-www-form-urlencoded"));
pFile->AddRequestHeaders(_T("Accept-Encoding: gzip, deflate"));
pFile->AddRequestHeaders(_T("Host: 172.7.18.100:9000"));
pFile->AddRequestHeaders(_T("Connection: Keep-Alive"));
pFile->AddRequestHeaders(_T("Cache-Control: no-cache"));
// 这里是要提交的数据
TCHAR szRequest[256] = _T("checkFlag=&cmsUrl=http%3A%2F%2F172.7.18.100%3A9000%2F&name=admin&pwd=12345&LoginType=2&LoginText=%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0");
pFile->SendRequest(NULL, 0, szRequest, _tcslen(szRequest)+1);
CString strStatus(_T(""));
if(pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strStatus))
{
AfxMessageBox(strStatus);
} m_htmlCtrl.CreateFromStatic(IDC_HTMLVIEW,this);
m_htmlCtrl.Navigate(_T("http://172.7.18.100:9000/index!WCIndex.action"));还是到了登陆的界面!
http抓包如下:
键 值
请求 POST /login!login.action?iType=2 HTTP/1.1
Accept text/html, application/xhtml+xml, */*
Referer http://172.7.18.100:9000/
Accept-Language zh-CN
User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Content-Type application/x-www-form-urlencoded
Accept-Encoding gzip, deflate
Host 172.7.18.100:9000
Content-Length 133
Connection Keep-Alive
Cache-Control no-cache
Cookie JSESSIONID=7351FE0358E560AA09BE6C9EC9E62BFF; username=admin; iType=2请求正文:
checkFlag=&cmsUrl=http%3A%2F%2F172.7.18.100%3A9000%2F&name=admin&pwd=12345&LoginType=2&LoginText=%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0