post the code of CString CWebWorld::GetWebPage(const CString& Url);

解决方案 »

  1.   

        HINTERNET hHttpFile;
        char szSizeBuffer[32];
        DWORD dwLengthSizeBuffer = sizeof(szSizeBuffer); 
        DWORD dwFileSize;
        DWORD dwBytesRead;
        BOOL bSuccessful;
        CString Contents;    // Setting default error message
        Contents = m_ErrorMessage;
        
        // Opening the Url and getting a Handle for HTTP file
        hHttpFile = InternetOpenUrl(m_Session, (const char *) Url, NULL, 0, 0, 0);    if (hHttpFile)
        {    
            // Getting the size of HTTP Files
            BOOL bQuery = ::HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH, szSizeBuffer, &dwLengthSizeBuffer, NULL) ;        if(bQuery==TRUE)
            {    
                // Allocating the memory space for HTTP file contents
                dwFileSize=atol(szSizeBuffer);
                LPSTR szContents = Contents.GetBuffer(dwFileSize);            // Read the HTTP file 
                BOOL bRead = ::InternetReadFile(hHttpFile, szContents, dwFileSize, &dwBytesRead); 
                
                if (bRead) 
                    bSuccessful = TRUE;            ::InternetCloseHandle(hHttpFile); // Close the connection.
            }    }
        else
        {
            // Connection failed.
            bSuccessful = FALSE;
        } 
        return Contents;
      

  2.   

        HINTERNET hHttpFile;
        char szSizeBuffer[32];
        DWORD dwLengthSizeBuffer = sizeof(szSizeBuffer); 
        DWORD dwFileSize;
        DWORD dwBytesRead;
        BOOL bSuccessful;
        CString Contents;    // Setting default error message
        Contents = m_ErrorMessage;
        
        // Opening the Url and getting a Handle for HTTP file
        hHttpFile = InternetOpenUrl(m_Session, (const char *) Url, NULL, 0, 0, 0);    if (hHttpFile)
        {    
            // Getting the size of HTTP Files
            BOOL bQuery = ::HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH, szSizeBuffer, &dwLengthSizeBuffer, NULL) ;        if(bQuery==TRUE)
            {    
                // Allocating the memory space for HTTP file contents
                dwFileSize=atol(szSizeBuffer);
                LPSTR szContents = Contents.GetBuffer(dwFileSize);            // Read the HTTP file 
                BOOL bRead = ::InternetReadFile(hHttpFile, szContents, dwFileSize, &dwBytesRead); 
                
                if (bRead) 
                    bSuccessful = TRUE;            ::InternetCloseHandle(hHttpFile); // Close the connection.
            }    }
        else
        {
            // Connection failed.
            bSuccessful = FALSE;
        } 
        return Contents;
      

  3.   

    The following works.
    bool SaveUrl(LPCTSTR url, LPCTSTR filename)
    {
    HINTERNET hNet = ::InternetOpen("Outlook",
    PRE_CONFIG_INTERNET_ACCESS,
    NULL,
    INTERNET_INVALID_PORT_NUMBER,
    0) ;

    HINTERNET hUrlFile = ::InternetOpenUrl(hNet,
    url,
    NULL,
    0,
    INTERNET_FLAG_RELOAD,
    0) ;

    char buffer[10*1024] ;
    DWORD dwBytesRead = 1;
    BOOL bRead=TRUE;
    CFile file;
    file.Open(filename,CFile::modeCreate|CFile::modeWrite);
    while(bRead&&dwBytesRead>0)
    {
    bRead = ::InternetReadFile(hUrlFile,
    buffer,
    sizeof(buffer),
    &dwBytesRead);
    if(dwBytesRead>0)
    file.Write(buffer,dwBytesRead);
    }
    ::InternetCloseHandle(hUrlFile) ;
    ::InternetCloseHandle(hNet) ;
    file.Close();
    AfxMessageBox("finished");
    return bRead;
    }
    void CC02021101Dlg::OnOK() 
    {
    // TODO: Add extra validation here
    bool bret=SaveUrl("http://club.pchome.net/bbs2.php?topic=40&lanmuid=2","C:\\temp\\test.html");
    if(bret)
    AfxMessageBox("true");
    else
    AfxMessageBox("false");
    }
      

  4.   

    BOOL bQuery = ::HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH, szSizeBuffer, &dwLengthSizeBuffer, NULL) ;
    Not all html page return correct file length, they may return -1! So sometimes you will fail. It is not related with php. The url "http://www.csdn.net/expert/Topic/465/465220.shtm" also return -1as I remembered.
      

  5.   

    to masterz():
    yes,u got it!