View Single Post
Old 03-14-2005, 04:16 AM   #5 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 705
DJMaze is on a distinguished road
I use this simple code in windows

Code:
#include <wininet.h>
#pragma link "lib/wininet.lib"

CString contents;
bool getwebdata(TCHAR *server, unsigned short port, TCHAR *uri) {
  HINTERNET hINet, hConnection, hData;
  char buffer[256];
  DWORD dwRead;

  hINet = InternetOpen(_T("Mozilla/1.0"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  if ( !hINet ) {
    return false;
  }
  try {
    hConnection = InternetConnect(hINet, server, port, _T(" "),_T(" "), INTERNET_SERVICE_HTTP, 0, 0);
    if ( !hConnection ) {
      InternetCloseHandle(hINet);
      return false;
    }

    // Get data
    hData = HttpOpenRequest(hConnection, "GET", uri, NULL, NULL, NULL,
            INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_RELOAD, 0);
    if ( !hData ) {
      InternetCloseHandle(hConnection);
      InternetCloseHandle(hINet);
      return false;
    }

    HttpSendRequest( hData, NULL, 0, NULL, 0);
    while( InternetReadFile(hData, buffer, 255, &dwRead) ) {
      if ( dwRead == 0 ) break;
      buffer[dwRead] = 0;
      contents += buffer;
    }
  }
  catch( ... ) {
    ShowMessage("Error sending/receiving data from internet");
//    e->ReportError();
//    e->Delete();
  }

  InternetCloseHandle(hConnection);
  InternetCloseHandle(hINet);
  InternetCloseHandle(hData);

  return true;
}
Donno if it works properly in VS2k3 but it gives you a rough idea how to use the Windows wininet library if your app is for use in Win OS
DJMaze is offline   Reply With Quote