Solved

View HTML Source

Posted on 2003-11-06
3
454 Views
Last Modified: 2008-02-01
how do i obtain html source from a web page using VC6++ ? i'm trying to do something like Internet explorer's view source.
Thanks.
0
Comment
Question by:Hsiang2k
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 250 total points
ID: 9699415
MSDN Says

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",
                                PRE_CONFIG_INTERNET_ACCESS,
                                NULL,
                                INTERNET_INVALID_PORT_NUMBER,
                                0) ;

HINTERNET hUrlFile = ::InternetOpenUrl(hNet,
                                "http://www.microsoft.com",
                                NULL,
                                0,
                                INTERNET_FLAG_RELOAD,
                                0) ;

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

::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;
      }
       do
       {
          // 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.
          else
             fwrite(szTemp, sizeof (char), dwSize , pFile);
       }   // do
      while (TRUE);
      fflush (pFile);
      fclose (pFile);
      return TRUE;
   }

Good Luck
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9699438
http://www.codeproject.com/useritems/hextract.asp - HTTP header and source extraction tool
0
 
LVL 1

Expert Comment

by:luvjd
ID: 9701030
Check the following example. I hope that will solve your problem!
http://www.codeproject.com/useritems/yahoo__account__via_http.asp?target=yahoo
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question