Web Content can be anything from HTML to XML,
A number of mechanisms for accessing Web content with just a few lines of code are available. Web content includes anything that is accessible via the HTTP protocol. Content can be HTML, but more importantly it can be XML, a document in some binary format or even raw data such a DBF file passed as a string. wwIPStuff supports most of the functionality that HTTP provides including GET and POST operations, secure communication over SSL/HTTPS and security via Basic Authentication.
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.prg
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.prg
This 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 or Raw (simply posts an unencoded raw buffer).
To send XML data to a server you can use the following code:
loHttp = CREATEOBJECT('wwhttp') loHttp.nHttpPostMode = 4 && Xml or Raw *** Load up the XML data any way you need lcXML = FILETOSTR("XmlData.xml") *** Set the POST buffer - Note: No name parameter, just the buffer loHttp.AddPostKey(lcXML) lcXmlResult = loHttp.HttpGet("http://www.west-wind.com/SomeXmlService.xsvc") IF (loHttp.nError # 0) RETURN ENDIF ShowXml(lcXmlResult)
If the data you send happens to be something other than XML and the server actually cares about the content type (in most situations it doesn't) you can also set the cContentType property. For example, to send a Zip file:
loHttp.cContentType = "application/x-zip-compressed"
loHttp = CREATEOBJECT('wwhttp') loHttp.HttpGet("http://www.west-wind.com/","","","c:\test.htm") IF loHttp.nError # 0 wait window loHttp.cErrorMsg return ENDIF *** Browse the file from local disk GoUrl("c:\test.htm")
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.