xHarbour Reference Documentation > Class Reference (textmode) xHarbour Developers Network  

TIpClientHttp()

Creates a new TIpClientHttp object.

Syntax

TIpClientHttp():new( <cUrl> ) --> oTIpClientHttp

Arguments

<cUrl>
This is a character string holding the URL of the HTTP server used to access files in the World Wide Web (WWW). It must be coded in this form:
   http://[<userID>:<password>@]<www.server.com>

Alternatively, a TUrl() object can be passed that is initialized with the HTTP server URL.

Return

The function returns a new TIpClientHttp object and method :new() initializes the object.

Description

Objects of the TIpClientHttp() class inherit from the generic internet client class TIpClient(). TIpClientHttp objects are used to communicate with an HTTP server. They use the Hyper Text Transfer Protocol (HTTP, RFC2616.TXT) for exchanging data between a local and a remote station on the World Wide Web (WWW). The address of the HTTP server must be provided as a URL string with method :new(). The URL is maintained by a TUrl() object, which is stored in the :oUrl instance variable.

The internet connection to the HTTP server must be established with the :open() method.

Once the internet connection is established (opened), data can be retrieved using the :readAll() method.

When all data is received, the internet connection must be closed with the :close() method.

Instance variables

:nConnTimeout
Numeric timeout value in milliseconds.
:nDefaultPort
Numeric port number.

Methods

:readAll() --> cURLContent
Retrieves all data from a URL.

Info

See also:THtmlDocument(), TIpClient(), TIpClientFtp(), TUrl()
Category: HTML functions , Internet functions , Object functions , xHarbour extensions
Source:tip\httpcln.prg
LIB:lib\xhb.lib
DLL:dll\xhb.dll

Example

// The example loads the Google search page and enters "xHarbour" as
// query data. The response from Google for the query is stored in a local
// HTML file.

    PROCEDURE Main
       LOCAL oHttp, cHtml, hQuery

       oHttp:= TIpClientHttp():new( "http://www.google.de/search" )

       // build the Google query
       hQUery := Hash()
       hSetCaseMatch( hQuery, .F. )

       hQuery["q"]    := "xHarbour"
       hQuery["hl"]   := "en"
       hQuery["btnG"] := "Google+Search"

       // add query data to the TUrl object
       oHttp:oUrl:addGetForm( hQuery )

       // Connect to the HTTP server
       IF oHttp:open()
          // downlowad the Google response
          cHtml   := oHttp:readAll()
          Memowrit( "Google_xHarbour.html", cHtml )

          oHttp:close()
          ? Len(cHtml), "bytes received "
          ?? "and written to file Google_xHarbour.html"
       ELSE
          ? "Connection error:", oHttp:lastErrorMessage()
       ENDIF
    RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe