本帖最后由 VisualEleven 于 2012-05-14 20:06:44 编辑

解决方案 »

  1.   

    用抓包工具抓个包,然后模拟提交数据即可。
    http://blog.csdn.net/visualeleven/article/details/6656224
      

  2.   

    Thanks
    不过还有一个疑问,我自动登陆后,怎么用CHtmlView打开网页呢?
      

  3.   

    貌似不行啊
    代码如下:        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