| West Wind Internet Protocols 4.68 |
| Access HTTP content over the Web |
The easiest way to grab Web content is using the HTTPGet method of wwIPStuff:
oHTTP=CREATEOBJECT("wwHTTP")
lcHTML = oHTTP.HTTPGet("http://www.west-wind.com/")
*** Do something with the HTML
ShowHTML( lcHTML ) && in wwUtils.prgHTTPGet is a high level method and is a very easy single method call to retrieve Web content. This example performs an HTTP GET as there is no data POSTed to the Web Server. You can add POST data like this:
oHTTP=CREATEOBJECT("wwHTTP")
oHTTP.AddPostKey("FirstName","Rick")
oHTTP.AddPostKey("LastName","Strahl")
oHTTP.AddPostKey("Company","West Wind Technologies")
*** Optionally add custom headers
oHTTP.cExtraHeaders = ;
"cache-control:private" + CHR(13) + CHR(10) +;
"Custom-Header: Custom value" + CHR(13) + CHR(10)
lcHTML = oHTTP.HTTPGet("http://www.west-wind.com/wconnect/TestPage.wwd")
*** Do something with the HTML
ShowHTML( lcHTML ) && in wwUtils.prgThis properly formats the HTTP POST buffer for sending the variables to the Web server which simulates an HTML form submission. You can use the nHTTPConnectType property to set the content type used - the default is URLEncoded, which is the same as HTML forms. Other types include: 2 - Multipart forms (used often for file uploads or for forms that contain lots of data) and 4 - XML (simply posts an unencoded raw buffer).
oHTTP = CREATEOBJECT("wwHTTP")
*** Connect to the server
oHTTP.HTTPConnect("www.west-wind.com")
*** Initialize the variables that will be filled by HTTPGetEx
lcHTML="" && Data buffer
lnText=0 && Size of the output to return - 0 means autosize
*** Send the POST data and retrieve HTTP result
lnResult =oHTTP.HTTPGetEx("/files/wwipstuff.zip",@lcHTML,@lnText,,;
"d:\temp\wwipstuff.zip")
IF lnResult # 0
? lnResult, oHTTP.cErrorMsg
RETURN
ENDIF
*** Display downloaded file
GoUrl("d:\temp\wwipstuff.zip")
oHTTP.HTTPClose() && Close the connection
Streaming to file allows you to bypass large memory usage as wwHTTP doesn't build up a large string but instead reads one buffer at a time and outputs it to disk.
If you're new to the HTTP protocol please note that the syntax for HTTPConnect is very different from HTTPGet's - you specify a domain name or IP address rather than the fully qualified URL that was specified in HTTPGet. The domain name/IP is specified in HTTPConnect with the link on the server being specified in the HTTPGetEx call.
Last Updated: 4/5/2005 |
Send topic feedback