wwHTTP::HTTPGet

Retrieves an HTTP request such as an HTML document or XML data from a Web server using standard URL syntax. Despite its name this method can also POST data to the server.

Method supports URL syntax including HTTPS access, port numbers and url based passwords. You can pass username and password information using the second and third parameters for Basic Authentication on the Web server.

The method can POST data to the server by calling AddPostKey() to calling HTTPGet. Any other properties of the wwIPStuff object that affect an HTTP connection (nHTTPPostMode,nHTTPConnectType etc.) can be set prior to calling this method with exception of the following that are retrieved from the URL:

HttpGet calls HttpGetEx() internally so check out that topic as well.

o.HttpGet(lcUrl, lcUsername, lcPassword, lcOutputFile)

Return Value

String - HTTP result, which most likely will be HTML, but can be whatever data the link returns. This includes XML and binary data like Word documents or even data files. On error this string will be blank and the nError and cErrorMsg properties will be set.

Parameters

lcUrl
The full URL you want to retrieve. This URL must include the protocol (HTTP or HTTPS for example) and the Domain Name or IP Address. Example:
http://www.west-wind.com/wwipstuff.asp

lcUserName
Optional - Username used for Basic Authentication

lcPassword
Optional - Password used for Basic Authentication

Note: for backward compatibility the second parameter can also be numeric specifying the size of the result buffer to be returned

lcFileName
An optional path into which to download the content into. If this parameter is used the return value from this method will always return blank and only the file is created on success. To check for errors, check the nError/cErrorMsg and the cResultCode properties.

Remarks

This method returns ASCII text only - HTML is uninterpreted and presented as text.

To send custom headers use cExtraHeader.

We recommend use of this method over HTTPGetEx() since it is much simpler and less prone to invalid parameter passing. HttpGetEx() needs to be used only if you need to stream output directly to a file.

Example

oHTTP=CREATEOBJECT("wwHttp")

lcHTML = oHTTP.HTTPGet("http://www.west-wind.com/")

*** Do something with the HTML
ShowHTML( lcHTML )  && wwUtils.prg


*** With a login and SSL and POSTing data to the server
oHTTP.AddPostkey("Name","Rick Strahl")
oHTTP.Addpostkey("Data","important message")

*** Optionally add custom headers
oHTTP.cExtraHeaders = ;
	oHTTP.cExtraHeaders + ;
	"cache-control: private" +CRLF +;
	"custom-header: custom data" + CRLF 

lcHTML = oHTTP.HTTPGet("https://www.west-wind.com/wc.wc?wwDemo~Authenticate",;
                       "joeuser","biteme")


See also:

Class wwHTTP | wwHTTP::cResultCode | wwHTTP::nerror


  Last Updated: 4/5/2005 | © West Wind Technologies, 2008