Page 1 of 1

Another C++ problem!

Posted: Mon Jul 19, 2004 9:03 pm
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)

Posted: Mon Jul 19, 2004 10:09 pm
by feyd
you're using WinMain.. that's not a console app.. it's a windows app.

Posted: Mon Jul 19, 2004 10:14 pm
by Joe
no worrys problem solved now!

feyd: Win32 can be used within consoles, try for youself

Posted: Mon Jul 19, 2004 10:19 pm
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...

Posted: Mon Jul 19, 2004 10:22 pm
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.

Posted: Mon Jul 19, 2004 10:26 pm
by feyd
Looks like you need to add an InternetReadFile() or InternetReadFileEx()

Posted: Mon Jul 19, 2004 10:27 pm
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 :)

Posted: Mon Jul 19, 2004 10:29 pm
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

Posted: Mon Jul 19, 2004 10:32 pm
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 ;)

Posted: Mon Jul 19, 2004 10:36 pm
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.