• Log in or sign up for an account here: https://www.sythe.org/login

GetPage in C++?

_charmz

Active Member
Banned
Joined
Feb 5, 2006
Sythe Gold
0
Messages
233
Location
US
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
 
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;
}
 
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;
 
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..
 
GetPage in C++?
Thanks, hope my code helped.
 
GetPage in C++?
AGAIN! SMR GOT HERE BEFORE ME! WHAT'S UP WITH MY SPEED? LOL, GOOD JOB SMR.....got any sausage???
 
Runescape Gamblingrunescape gambling
Back
Top