Solved

View HTML Source

Posted on 2003-11-06
3
450 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

820 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