我想达到如下目的,在我的程序中填好用户名和密码,点确定后
就可以登陆到指定的论坛,并且自动用IE打开进入论坛首页。
例如我想进入动网论坛:
这是登陆页面:
http://bbs.dvbbs.net/login.asp
在我的程序中输入用户名和密码,确定后,会自动把IE打开并进入论坛首页:
http://bbs.dvbbs.net/index.asp
前面post密码和用户部分已经实现。程序片断如下:
strPostData.Format("username=%s&password=%s",m_strUsername,m_strPassword);
pFile=pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strNewObject);
pFile->AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
pFile->AddRequestHeaders("Accept: */*");
pFile->AddRequestHeaders("User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
pFile->SendRequest(NULL,0,(LPVOID)(LPCTSTR strPostData,strPostData.GetLength());
while (pFile->ReadString(strContent)) 
{
strContent+="\r\n";
nLength=m_editContent.GetWindowTextLength();
m_editContent.SetSel(nLength,nLength);
m_editContent.ReplaceSel(strContent);
}
调试发现已经正常接收到返回的数据,但是接下来不知道该如何实现
自动打开IE并进入论坛首页的过程,
难道要先把返回的内容在本地存为一个html文件,然后用
ShellExecute函数指定IE打开这个文件?不知道有没有更直接更好的方法?
请各位大虾指教,不胜感谢!

解决方案 »

  1.   

    void CCSDNDlg::OnLogin()
    {
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);
    TCHAR szTempPath[MAX_PATH],szTempFile[MAX_PATH];
        DWORD dwResult=::GetTempPath(MAX_PATH,szTempPath);
    CString strLoginPath;
    GetTempFileName(szTempPath,_T("DigitalTitan_"),0,szTempFile);
    strLoginPath=szTempFile;
    CFile m_File;
    CFileException m_FileException;
    m_File.Open(strLoginPath,CFile::modeWrite|CFile::modeCreate|CFile::typeText,&m_FileException);
    char pBuf[1024];
    sprintf(pBuf,"%s","<body onload='document.forms[0].submit();' bgcolor='DEE3F7'><form method='post' action='Http://expert.csdn.net/member/logon.asp'><input type='hidden' name='name' value='gjd111686'><input type='hidden' name='pass' value='DigitalTitan'><input type='hidden' name='from' value='http://expert.csdn.net/expert/deeptree/contentbar.asp?xmlsrc=/Expert/deeptree/Rooms/List.xml&csdnstyle=&hidetoc=false&myie=ie'></form></body>");
    m_File.Write(pBuf,strlen(pBuf));
    m_File.Close();
    m_IE.Navigate(strLoginPath,COleVariant(""),COleVariant(""),COleVariant(""),COleVariant(""));
    }
      

  2.   

    注意:
    <input type='hidden' name='from' value='http://expert.csdn.net/expert/deeptree/contentbar.asp?xmlsrc=/Expert/deeptree/Rooms/List.xml&csdnstyle=&hidetoc=false&myie=ie'>此域存放返回URL.
    如果你用SendRequest来提交自己构造的表单就需要同时提交表单域<input type='hidden' name='from' value='http://expert.csdn.net/expert/deeptree/contentbar.asp?xmlsrc=/Expert/deeptree/Rooms/List.xml&csdnstyle=&hidetoc=false&myie=ie'>而且它的值是value中描述的.
      

  3.   

    很简单,用程序打开这个网址,就可以实现登陆了,
    把我的用户名和密码改为你的.
    http://bbs.dvbbs.net/login.asp?action=chk&username=test1088&password=2311088
      

  4.   

    最简单的就是这样调用:
    WinExec("c:\\program files\\internet explorer\\IEXPLORE.EXE http://bbs.dvbbs.net/login.asp?action=chk&username=test1088&password=2311088",SW_SHOW);
      

  5.   

    gjd111686(数字金刚) ( ) 
    请问m_IE是个什么类的对象?为什么要建一个临时文件?
    另外其中的密码不是真的吧,呵呵prettywolf(多情自古空余恨,此恨绵绵无绝期)
    你的方法对于动网的是可以的,但是用的是get方法,不是很安全,我需要
    post方法,而且对于有些论坛用这种方法进不去,非要用表单的post方式
    才能登陆。
      

  6.   

    用shell不可以吧?
    有很多论坛对密码都有加密的。