L_InetHttpConnect

#include "ltweb.h"

L_LTWEB_API L_INT L_InetHttpConnect(pszServer, iPort, pszUserName, pszPassword, pHttp)

L_TCHAR *pszServer;

/* name of server to connect to*/

L_INT iPort;

/* port number to connect to*/

L_TCHAR *pszUserName;

/* username for authentication*/

L_TCHAR *pszPassword;

/* password for authentication*/

pHINET pHttp

/* address of the variable to be updated*/

Connects to an HTTP server.

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).

iPort

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

pszUserName

Character string containing the username to be used for authentication.

pszPassword

Character string containing the password to be used for authentication.

pHttp

Address of the variable to be updated with the Http connection.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Use this function to establish a connection with an HTTP Server. To connect anonymously pass NULL for pszUserName and pszPassword.

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:

L_InetHttpDisconnect, L_InetHttpCloseRequest

Topics:

HTTP Functions: HTTP Connections

 

Working with HTTP Functions

Example

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

 L_INT InetHttpConnectExample(L_VOID)
{
   HINET hInet;
   L_INT nRet;
   NAMEVALUE nv[2];
   DWORD dwSizeWrite;

   nRet = L_InetHttpConnect(TEXT("www.leadtools.com"),80,TEXT(""),TEXT(""),&hInet);
   if(nRet==SUCCESS)
   {
      nRet = L_InetHttpOpenRequest(hInet,HTTP_POST,TEXT("/form.asp"),TEXT(""),TEXT("HTTP/1.0"),0);
      if(nRet==SUCCESS)
      {
         L_TCHAR szResponse[2048];
         L_UINT32 lsize;
         L_UINT uStatus;
         HANDLE fp;

         nv[0].pszName = TEXT("email");
         nv[0].pszValue = TEXT("myemail@somewhere.com");
         nv[1].pszName = TEXT("name");
         nv[1].pszValue = TEXT("First Last");
    
         nRet=L_InetHttpSendForm(hInet,nv,2); 
         if(nRet!=SUCCESS)
         {
            MessageBox(NULL, TEXT("Error Sending Form"), TEXT("Error"),MB_ICONEXCLAMATION);
            nRet = L_InetHttpCloseRequest(hInet);
            if(nRet != SUCCESS)
               return nRet;
            nRet = L_InetHttpDisconnect(hInet);
            if(nRet != SUCCESS)
               return nRet;
            return nRet;
         }

         nRet = L_InetHttpGetServerStatus(hInet,&uStatus);
         if(nRet != SUCCESS)
            return nRet;
         if(uStatus==L_HTTP_STATUS_OK)
         {
            lsize = 2048;
            nRet = L_InetHttpGetResponse(hInet,(L_CHAR *)szResponse,&lsize);
            if(nRet != SUCCESS)
               return nRet;
           
            fp =CreateFile(TEXT("output.htm"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
    
            while(lsize!=0)
            {
               WriteFile(fp,szResponse, lsize, &dwSizeWrite, NULL); 
               lsize = 1048;
               nRet = L_InetHttpGetResponse (hInet,(L_CHAR *)szResponse,&lsize);
               if(nRet != SUCCESS)
                  return nRet;
            }
            CloseHandle(fp);
         }
         else
            MessageBox(NULL,TEXT("Problem With Server"), TEXT("Error"),MB_ICONEXCLAMATION);
         nRet = L_InetHttpCloseRequest(hInet); 
         if(nRet != SUCCESS)
            return nRet;
      }
      else
         return nRet;
      nRet = L_InetHttpDisconnect(hInet);
      if(nRet != SUCCESS)
         return nRet;
   }
   else 
      return nRet;
   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>
*/