wwHTTP::HTTPGetEx

This method is the full featured HTTP access method that provides full support for the HTTP protocol including POST data, Basic Authentication and HTTPS protocol support. Requires HTTPConnect() to open a connection first and HTTPClose() to shut down.

Note: Use HTTPGet instead!
HttpGet provides most of the functionality of the low level HttpConnect/HttpGetEx combo, but is easier and more reliable as it handles all the connection setup/cleanup automatically.

o.HTTPGetEx(tcPage, @tcBuffer, @tnBufferSize, tcHeaders, tcFileName)

Return Value

0 on success, an error number on failure.

Parameters

tcPage
The Web server relative link to retrieve. Typically this will be an HTML page or a script page. Example: /wonnect/default.htm

@tcBuffer
This is the result buffer that will contain data retrieved from the Web server. The size of this buffer depends on the input and output values of tnBufferSize

@tnBufferSize
This value determines the size of the result buffer returned. Pass in a size and HTTPGetEx will only return that many bytes or less. Pass in 0 and the buffer is dynamically sized to the request's size. On output this value will contain the actual size of the HTTP response.

tcHeaders
Optional - Allows you to specify custom HTTP headers to send to the server. Note these are client side headers. Example:

"Referer: http://myserver.com/somelink.htm" + CRLF + ;
"User-Agent: Rick's great Browser V1.0" +CRLF +;
"Custom: Wonk it!"

Easier: Use the AddHeader() method to add headers.

tcFileName
Optional - A filename to cause the captured data to be streamed directly to a file rather than into the @tcBuffer variable. Use this for strings that will be large such as file downloads. tcBuffer must be passed in as "" and the size as 0 for this option to work

Remarks

HTTPGetEx also supports an optional 'event method' interface. You can subclass wwIPStuff and implement a method called OnHTTPBufferUpdate() in which case this method is called whenever wwIPStuff receives a chunk of data.

When the result returns you can also retrieve cHTTPHeader to see any HTTP headers that were returned from the server.

Other properties to check out:

nHTTPPort - If you want to use other ports than 80/443 nHTTPPostMode - URL Encoded or MultiPart forms cHTTPHeaders - Returns HTTP headers of the result nHTTPWorkBufferSize - Size of the chunks that HTTPGetEx uses to read data from the server lHTTPCancelDownload - Flag that can be set to cancel a HTTPGetEx request cResultCode - HTTP Header result code (200,500,404 etc.) that you can use to check for additional

Example

oHTTP = CREATEOBJECT("wwHttp")

*** Connect to the server
oHTTP.HTTPConnect("www.west-wind.com")

*** Let's post some data TO the server
oHTTP.AddPostKey("Client","B")
oHTTP.AddPostKey("FromDate","01/01/96")

*** Initialize the variables that will be filled by HTTPGetEx
lcHTML=""
lnText=0

*** Send the POST data and retrieve HTTP result
lnResult=oHTTP.HTTPGetEx("/wconnect/wc.dll?wwDemo~ShowHours",;
                         @lcHTML,@lnText)
IF lnResult # 0
   ? lnResult, oHTTP.cErrorMsg
   RETURN
ENDIF


? TRIM(lcHTML)
* ShowHTML( lcHTML )


oHTTP.HTTPClose()   && Close the connection

See also:

West Wind Web Connection | wwHTTP::AddPostkey | wwIPStuff::OnHTTPBufferUpdate | wwIPStuff::HTTPGetHeader | wwIPStuff::HTTPGetEx |

© West Wind Technologies, 1996-2018 • Updated: 11/30/17
Comment or report problem with topic