GetPage in C++?

Discussion in 'Programming General' started by _charmz, Oct 9, 2008.

GetPage in C++?
  1. Unread #1 - Oct 9, 2008 at 12:15 AM
  2. _charmz
    Joined:
    Feb 5, 2006
    Posts:
    233
    Referrals:
    0
    Sythe Gold:
    0

    _charmz Active Member
    Banned

    GetPage in C++?

    I basicly need a function that will that will grab the HTML from any webpage and place it into a string (or?) Teach me how to do it, or give me the function please. I have been looking all over the internet but nothing has helped yet :(.

    I want to copy what GetPage from SCAR does, if you are familar with it.

    Thank You
     
  3. Unread #2 - Oct 13, 2008 at 12:13 AM
  4. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    GetPage in C++?

    Code:
    #include <windows.h>
    #include <wininet.h>
    #pragma comment(lib,"wininet.lib")
    #include <string>
    using namespace std;
    
    string GetPage(LPCSTR server, LPCSTR path)
    {
    	DWORD dwRead;
    	HINTERNET hSession = InternetOpen("GetPage/1.0",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
    	HINTERNET hConnection = InternetConnect(hSession,server,INTERNET_DEFAULT_HTTP_PORT,"","",INTERNET_SERVICE_HTTP,0,0);
    	if(!hConnection)
    	{
    		MessageBox(NULL,"An error occured while trying to connect to the host specified.",NULL,MB_OK);
    		SetLastError(ERROR_CONNECTION_INVALID);
    		return "Error opening site";
    	}
    	HINTERNET hData = HttpOpenRequest(hConnection,"GET",path,NULL,NULL,NULL,INTERNET_FLAG_KEEP_CONNECTION,0);
    	HttpSendRequest(hData,NULL,0,NULL,0);
    	CHAR pageContents[2048];
    	string retVal;
    	while(InternetReadFile(hData,pageContents,255,&dwRead))
    	{
    		if(dwRead==0)
    		{
    			break;
    		}
    		pageContents[dwRead]=0;
    		retVal+=pageContents;
    	}
    	InternetCloseHandle(hConnection);
    	InternetCloseHandle(hSession);
    	return retVal;
    }
     
  5. Unread #3 - Oct 13, 2008 at 12:18 AM
  6. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    GetPage in C++?

    And, as you may have deduced: server is the name of the site to connect to, and path is the remote file path. A valid call would be:

    string s = GetPage("www.sythe.org","/index.php");
    cout << s;
     
  7. Unread #4 - Oct 13, 2008 at 2:37 PM
  8. _charmz
    Joined:
    Feb 5, 2006
    Posts:
    233
    Referrals:
    0
    Sythe Gold:
    0

    _charmz Active Member
    Banned

    GetPage in C++?

    Code:
    #using <System.dll>
    
    using namespace System;
    using namespace System::IO;
    using namespace System::Net;
    using namespace System::Text;
    
    int main()
    {
    
       // Create a request for the URL.   
       WebRequest^ request = WebRequest::Create( "http://www.contoso.com/default.html" );
    
       // If required by the server, set the credentials.
       request->Credentials = CredentialCache::DefaultCredentials;
    
       // Get the response.
       HttpWebResponse^ response = dynamic_cast<HttpWebResponse^>(request->GetResponse());
    
       // Display the status.
       Console::WriteLine( response->StatusDescription );
    
       // Get the stream containing content returned by the server.
       Stream^ dataStream = response->GetResponseStream();
    
       // Open the stream using a StreamReader for easy access.
       StreamReader^ reader = gcnew StreamReader( dataStream );
    
       // Read the content.
       String^ responseFromServer = reader->ReadToEnd();
    
       // Display the content.
       Console::WriteLine( responseFromServer );
    
       // Cleanup the streams and the response.
       reader->Close();
       dataStream->Close();
       response->Close();
    
       return 0;
    }
    
    lol i was trying to do it this was but i keep getting errors with #using, urs is true unmanaged c++, thank you, i was trying to use managed..
     
  9. Unread #5 - Oct 13, 2008 at 3:10 PM
  10. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    GetPage in C++?

    Thanks, hope my code helped.
     
  11. Unread #6 - Oct 13, 2008 at 9:51 PM
  12. exapto
    Joined:
    Oct 10, 2008
    Posts:
    645
    Referrals:
    0
    Sythe Gold:
    123
    Vouch Thread:
    Click Here
    Discord Unique ID:
    716746285151027321
    Discord Username:
    exapto#2360
    Homosex

    exapto #1 OSRS Magic Training Service
    $50 USD Donor New

    GetPage in C++?

    AGAIN! SMR GOT HERE BEFORE ME! WHAT'S UP WITH MY SPEED? LOL, GOOD JOB SMR.....got any sausage???
     
< need help with file extraction PLZ | C++ exit program >

Users viewing this thread
1 guest


 
 
Adblock breaks this site