[SOLVED] Another C++ problem!

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Another C++ problem!

Post by Joe »

Yes everyone it is another one of my C++ questions :) I know this is not the place but the last time I asked for help on C++ here I got bundles of help from other members. Anyway, the problem is that I wish to send a GET request so the source of the selected page is shown to the screen, much like get() in perl. Everything works excellent but instead of displaying the source it shows either 1 or 0. Where 1 is true and 0 is false.

Code: Select all

#include <iostream.h>
#include <wininet.h>
#include <windows.h>

#define  NET_ADDR   "IP-WILL-GO-HERE"

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) 
&#123;
 HINTERNET hINEt,hConnection,hData;
 
 hINEt = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
 if (!hINEt) &#123; cout<<"Internet open failed. Please try again!\n"; &#125;
  
 hConnection = InternetConnect(hINEt, NET_ADDR, 80, " "," ", INTERNET_SERVICE_HTTP, 0, 0);
 
 if (!hConnection) 
 &#123; 
  cout<<"Internet Connection error...\n"; 
  InternetCloseHandle(hINEt); 
 &#125;
 
 hData = HttpOpenRequest(hConnection, "GET", "/Tutorials/section.php", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);                 
  
 cout<<HttpSendRequest( hData, NULL, 0, NULL, 0);
&#125;
Can anyone recommend any techniques in C++ please to show the source to the console.

Regards


Joe 8)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're using WinMain.. that's not a console app.. it's a windows app.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

no worrys problem solved now!

feyd: Win32 can be used within consoles, try for youself
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I know that... it's just a lot easier to get a console app with standard systems.

btw, cout shouldn't be available the way you wrote the code..

try adding

Code: Select all

// includes...

using std::cout; // or something, can't quite remember, I haven't used cout in years.

// functions
BOOL HttpSendRequest(
HINTERNET hRequest,
LPCTSTR lpszHeaders,
DWORD dwHeadersLength,
LPVOID lpOptional,
DWORD dwOptionalLength
);
HttpSendRequest returns a TRUE/FALSE.. not a text stream...
Last edited by feyd on Mon Jul 19, 2004 10:23 pm, edited 1 time in total.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Yes thats a standard cout for the I/O library. Its used regularly I must admit but throughout my time of C++ I have managed to get away without using it.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Looks like you need to add an InternetReadFile() or InternetReadFileEx()
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Where 1 is true and 0 is false.
Can anyone recommend any techniques in C++
Yes thats the problem. I was looking for a new technique to do my work :)
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

No im not wanting to read the file manually, instead I am trying to send a request to get the contents. This is just some work from bordom. Nothing big or anything lol
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it looks like that's the only way to get the contents.. with the quick look I did through the internet functions.. I haven't needed to use those in my past work, so not very sure.. If it involved DirectX, or the Registry, or setting it up for Windows Compliance.. I could be of more help ;)
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

OK man thanks a bunch. Much appreciated.

Problem Solved: I created a socket and used snprintf(). It worked great for some reason I do not know.
Post Reply