Solved

View HTML Source

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now