网页上有一个填写帐号密码表单的地方,用程序发送帐号密码进行登录,小弟不太会。我有几个选择,请大家指教一下: 
方法1: 
IXMLHTTPRequestPtr  xmlreq; 
xmlreq->open(_bstr_t("POST"),_bstr_t(Url),true,user,password); 
xmlreq->send(); 
这个方法我不太明确,open里面加入帐号密码的参数,能发送到网页的表单里么。 方法2: 
WinInet成员函数:InetrnetOpen  HttpOpenRequest  HttpSendRequert(Ex) 这种方法没找到在哪里填入帐号密码参数的地方。如果是这个方法,请给出具体代码 方法3: 
CHttpFile类  如果是这个方法,请给出具体代码。 方法4: 
MFC对话框加入一个WebBrowser控件,可是不会用这个控件,控件是添加了,可不知道怎样在程序中调用这个控件 以上方法请大侠们指点一下,哪些方法可以实现,并给出具体代码,尽量多一点代码供小弟参考. 不胜感激 还有,以上某个方法实现了帐号密码登录之后,要想通过点击按钮或者复选框标签才能获得信息的话,要通过什么方式或方法呢,请告知

解决方案 »

  1.   

    这个起用CHttpFile就行了,给你一个现成的函数吧://****************************************************************************************//
    //函数 PostData
    //主要功能: Post方式向服务器传数据
    //参数列表: 
    //    1、strUrl:提交地址
    //    2、strPara:提交的参数
    //    3、strContent:返回的网页内容
    //返回值: 如果成功则返回true
    //备注: 
    //****************************************************************************************//
    bool PostData(CString strUrl, const CString &strPara, CString &strContent)
    {
        bool bRet = false;
        CString strServer, strObject, strHeader, strRet;
        unsigned short nPort;
        DWORD dwServiceType;
        if(!AfxParseURL(strUrl, dwServiceType, strServer, strObject, nPort))//不是有效有网络地址!
            return false;    CInternetSession sess;//Create session
        CHttpFile* pFile = NULL;
        CHttpConnection *pServer = sess.GetHttpConnection(strServer, nPort); 
        if(pServer == NULL)//连接服务器失败!
            return false;    pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strObject,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT); 
        if(pFile == NULL)//找不到网络地址
            return false;    pFile -> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded"); 
        pFile -> AddRequestHeaders("Accept: */*"); 
        pFile -> SendRequest(NULL,0,(LPTSTR)(LPCTSTR)strPara, strPara.GetLength());     CString strSentence;
        DWORD dwStatus;
        DWORD dwBuffLen = sizeof(dwStatus);
        BOOL bSuccess = pFile->QueryInfo(
            HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
            &dwStatus, &dwBuffLen);    if( bSuccess && dwStatus>=  200 && dwStatus<300) 
        {
            char buffer[2049];
            memset(buffer, 0, 2049);
            int nReadCount = 0;
            while((nReadCount = pFile->Read(buffer, 2048)) > 0)
            {
                strContent += buffer;
                memset(buffer, 0, 2049);
            }
            bRet = true;
        }
        else//错误
            bRet = false;
        pFile->Close();
        sess.Close();
        return bRet;
    }上面的函数中参数说明:
    1、strUrl:表单提交的地址,也不是你查看网页原文件时可以以那个<form 中的action所指向的地址,需要完整的绝对地址。
    2、strPara:这个参数时表单的内容,可以查网页原文件,查看各个表单的名字再自己写上值,比如你的表单中只有用户名(username)和密码(password),则这个参数可以是:username=mytest&password=123456
    3、strContent:是提交以后返回的网页的内容
      

  2.   

    用curl库,功能强大非常好用。#include <stdio.h>
    #include <curl/curl.h>int main(void)
    {
      CURL *curl;
      CURLcode res;  curl = curl_easy_init();
      if(curl) {
        /* First set the URL that is about to receive our POST. This URL can
           just as well be a https:// URL if that is what should receive the
           data. */
        curl_easy_setopt(curl, CURLOPT_URL, "http://postit.example.com/moo.cgi");
        /* Now specify the POST data */
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");    /* Perform the request, res will get the return code */
        res = curl_easy_perform(curl);    /* always cleanup */
        curl_easy_cleanup(curl);
      }
      return 0;
    }