LInetHttp::LInetHttp

#include "ltwrappr.h"

L_VOID LInetHttp::LInetHttp(L_VOID)

L_VOID LInetHttp::LInetHttp(pszServer, pszUserName = NULL, pszPassword = NULL, nPort = 80)

L_TCHAR L_FAR *pszServer;

/* name of server to connect to */

L_TCHAR L_FAR *pszUserName;

/* username for authentication */

L_TCHAR L_FAR *pszPassword;

/* password for authentication */

L_INT nPort;

/* port number to connect to */

Constructs and initializes the member variables of the LInetHttp object.

Parameter

Description

pszServer

Character string that contains the name of the server to which to connect. The name can be a network name, an IP address, or a domain name (www.leadtools.com).

pszUserName

Character string containing the username to be used for authentication. Default value is NULL.

pszPassword

Character string containing the password to be used for authentication. Default value is NULL.

nPort

Number of the port to which to connect. The default port assignment for web servers is 80.

Returns

None

Comments

LInetHttp::LInetHttp() is the default LInetHttp constructor. After calling the this constructor, a user must call LInetHttp::Connect to establish a connection before using other functions.

LInetHttp::LInetHttp(pszServer, pszUserName = NULL, pszPassword = NULL, nPort = 80) is a constructor for the LInetHttp object. It connects to the HTTP server. If both pszUserName and pszPassword are NULL, the connection is made anonymously.

A connection to an HTTP server must be established before using any other HTTP functions. If a connection is disconnected, via either LInetHttp::Disconnect or LInetHttp::~LInetHttp, then a connection must be re-established before any other HTTP functions are called. LInetHttp::Connect and LInetHttp::LInetHttp can be used to establish a connection with an HTTP server.

Required DLLs and Libraries

LTWEB

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application

See Also

Functions:

LInetHttp::~LInetHttp, LInetHttp::Connect,

Topics:

HTTP Functions: Connect / Disconnect Operations

 

How to Program with the LInetHttp Class

Example

//This example for LInetHttp::LInetHttp(L_VOID)

// This will call the default constructor and destructor when it is out of scope

LInetHttp InetHttp();
// other code

//-----------------------------------------------------------------------------------------------------------------------
/*
This example for LInetHttp::LInetHttp(pszServer, pszUserName = NULL, pszPassword = NULL, nPort = 21)*/

// This example simulates posting a form to a web site

L_VOID TestFunction(HWND hWndParent)
{
   L_UINT uStatus;
   FILE *pFILE;
   NAMEVALUE nv[2];
   LBuffer Response;
   L_UINT ulSize;

   nv[0].pszName = TEXT("email");
   nv[0].pszValue = TEXT("support@leadtools.com");
   nv[1].pszName = TEXT("name");
   nv[1].pszValue = TEXT("First Last");

   LInetHttp InetHttp(TEXT("www.leadtools.com"));

   // Checking if the connection failed
   if(InetHttp.GetErrorFromList () != SUCCESS)
   {
      InetHttp.DisplayError (hWndParent, TEXT("Can't connect to the HTTP web server"));
      return;
   }

   if(InetHttp.OpenRequest (HTTP_POST, TEXT("/form.asp")) != SUCCESS)
   {
      InetHttp.DisplayError (hWndParent, TEXT("Can't open a request"));
      return;
   }

   if(InetHttp.SendForm (nv, 2) != SUCCESS)
   {
      InetHttp.DisplayError(hWndParent, TEXT("Error while send the form"));
      return;
   }

   uStatus = InetHttp.GetServerStatus ();

   // Checking if the an error occurred
   if(InetHttp.GetErrorFromList () != SUCCESS)
   {
      InetHttp.DisplayError (hWndParent, TEXT("Can't get the server status, the connection may refused"));

      InetHttp.GetResponse (&Response);
      ulSize = Response.GetSize();

      #ifdef UNICODE

         pFILE = _wfopen(TEXT("error.htm"),TEXT("wb"));
      #else

         pFILE = fopen("error.htm","wb");
      #endif

      while(ulSize != 0)
      {
         fwrite(Response.Lock (), ulSize, 1, pFILE);
         Response.Unlock ();

         InetHttp.GetResponse(&Response);
         ulSize = Response.GetSize ();
      }
      fclose(pFILE);

      return;
   }

   if(uStatus == L_HTTP_STATUS_OK)
   {

      if(InetHttp.GetResponse (&Response) != SUCCESS)
      {
         InetHttp.DisplayError (hWndParent, TEXT("Can't get the server reponse, the connection may refused"));
         return;
      }

      ulSize = Response.GetSize();

      #ifdef UNICODE

         pFILE = _wfopen(TEXT("output.htm"),TEXT("wb"));
      #else

         pFILE = fopen("output.htm","wb");
      #endif

      while(ulSize != 0)
      {
         fwrite(Response.Lock(), ulSize, 1, pFILE);
         InetHttp.GetResponse(&Response);
         ulSize = Response.GetSize ();
      }
      fclose(pFILE);
   }
}

Here is a sample form.asp that can be used with this sample
.

<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<BODY>
 <table>
  <tr>
   <td>Email:</td>
   <td><% Response.Write Request("Email")%></td>
  </tr>
  <tr>
   <td>Name:</td>
   <td><% Response.Write Request("Name")%></td>
  </tr>
 </table>
</BODY>
<HTML>