LInetHttp::LInetHttp

#include "ltwrappr.h"

L_VOID LInetHttp::LInetHttp(L_VOID)

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

L_TCHAR *pszServer;

/* name of server to connect to */

L_TCHAR *pszUserName;

/* username for authentication */

L_TCHAR *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
L_INT LInetHttp_LInetHttpExample_1()
{
   LInetHttp InetHttp;
   // other code
   return SUCCESS;
}
//-----------------------------------------------------------------------------------------------------------------------
/*This example for LInetHttp::LInetHttp(pszServer, pszUserName = NULL, pszPassword = NULL, nPort = 21)*/
// This example simulates posting a form to a web site
L_INT LInetHttp_LInetHttpExample_2(HWND hWndParent)
{
   L_INT       nRet;
   L_UINT      uStatus;
   HANDLE      pFile;
   NAMEVALUE   nv[2];
   LBuffer     Response;
   L_UINT      ulSize;
   DWORD       dwSizeWrite;
   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
   nRet = InetHttp.GetErrorFromList ();
   if(nRet != SUCCESS)
   {
      InetHttp.DisplayError (hWndParent, TEXT("Can't connect to the HTTP web server"));
      return nRet;
   }
   nRet = InetHttp.OpenRequest (HTTP_POST, TEXT("/form.asp"));
   if(nRet != SUCCESS)
   {
      InetHttp.DisplayError (hWndParent, TEXT("Can't open a request"));
      return nRet;
   }
   nRet = InetHttp.SendForm (nv, 2);
   if(nRet != SUCCESS)
   {
      InetHttp.DisplayError(hWndParent, TEXT("Error while send the form"));
      return nRet;
   }
   uStatus = InetHttp.GetServerStatus ();
   // Checking if the an error occurred
   nRet = InetHttp.GetErrorFromList ();
   if(nRet != SUCCESS)
   {
      InetHttp.DisplayError (hWndParent, TEXT("Can't get the server status, the connection may refused"));
      InetHttp.GetResponse (&Response); 
      ulSize = (L_UINT) Response.GetSize();
      pFile = CreateFile(TEXT("C:\\Program Files\\LEAD Technologies, Inc\\LEADTOOLS 16\\Images\\error.htm"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
      while(ulSize != 0) 
      {
         WriteFile(pFile, Response.Lock (), ulSize, &dwSizeWrite, NULL); 
         Response.Unlock ();
         InetHttp.GetResponse(&Response); 
         ulSize = (L_UINT) Response.GetSize ();
      }
      CloseHandle(pFile); 
      return nRet; 
   }
   if(uStatus == L_HTTP_STATUS_OK)
   {
      nRet = InetHttp.GetResponse (&Response);
      if(nRet != SUCCESS)
      {
         InetHttp.DisplayError (hWndParent, TEXT("Can't get the server reponse, the connection may refused"));
         return nRet;
      }
      ulSize = (L_UINT) Response.GetSize();
      pFile = CreateFile(TEXT("C:\\Program Files\\LEAD Technologies, Inc\\LEADTOOLS 16\\Images\\output.htm"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
      while(ulSize != 0)
      {
         WriteFile(pFile, Response.Lock (), ulSize, &dwSizeWrite, NULL); 
         InetHttp.GetResponse(&Response);
         ulSize = (L_UINT) Response.GetSize ();
      }
      CloseHandle(pFile);
   }
   return SUCCESS;
}
/*************************************************************************
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>
*************************************************************************/