View HTML Source

how do i obtain html source from a web page using VC6++ ? i'm trying to do something like Internet explorer's view source.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roshan DavisCommented:

The best way to approach the Win32 Internet functions is to jump right into the code. The code below is sample code, with error handling removed for readability.

HINTERNET hNet = ::InternetOpen("MSDN SurfBear",
                                0) ;

HINTERNET hUrlFile = ::InternetOpenUrl(hNet,
                                0) ;

char buffer[10*1024] ;
DWORD dwBytesRead = 0;
BOOL bRead = ::InternetReadFile(hUrlFile,

::InternetCloseHandle(hUrlFile) ;

::InternetCloseHandle(hNet) ;

The code listing above contains four Internet functions: InternetOpen, InternetOpenUrl, InternetReadFile, and InternetCloseHandle

BOOL GetFile (HINTERNET IN hOpen, // Handle from InternetOpen()
                 CHAR *szUrl,        // Full URL
                 CHAR *szFileName)   // Local file name
       DWORD dwSize;
       CHAR   szHead[] = "Accept: */*\r\n\r\n";
       VOID * szTemp[25];
       HINTERNET  hConnect;
      FILE * pFile;

       if ( !(hConnect = InternetOpenUrl ( hOpen, szUrl, szHead,
             lstrlen (szHead), INTERNET_FLAG_DONT_CACHE, 0)))
         cerr << "Error !" << endl;
           return 0;

       if  ( !(pFile = fopen (szFileName, "wb" ) ) )
           cerr << "Error !" << endl;
          return FALSE;
          // Keep coping in 25 bytes chunks, while file has any data left.
          // Note: bigger buffer will greatly improve performance.
          if (!InternetReadFile (hConnect, szTemp, 50,  &dwSize) )
              fclose (pFile);
             cerr << "Error !" << endl;
            return FALSE;
          if (!dwSize)
              break;  // Condition of dwSize=0 indicate EOF. Stop.
             fwrite(szTemp, sizeof (char), dwSize , pFile);
       }   // do
      while (TRUE);
      fflush (pFile);
      fclose (pFile);
      return TRUE;

Good Luck

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roshan DavisCommented: - HTTP header and source extraction tool
Check the following example. I hope that will solve your problem!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.