| xHarbour Reference Documentation > Class Reference (textmode) |
![]() |
![]() |
![]() |
Creates a new TIpClientHttp object.
TIpClientHttp():new( <cUrl> ) --> oTIpClientHttp
http://[<userID>:<password>@]<www.server.com>
Alternatively, a TUrl() object can be passed that is initialized with the HTTP server URL.
The function returns a new TIpClientHttp object and method :new() initializes the object.
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.
| 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 |
// 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
http://www.xHarbour.com