|
|||||
|
|||||
HTTP clients, creating |
This sample program illustrates a common use of the HTTP library on the client side. It will connect to a given web page (in this case, the Stilo website's home page) and scan the page for a given pattern ("OmniMark").
The HttpRequestSend
function will handle all aspects of the connection, including error handling.
;Declaring the function library: include "omhttp.xin" ;scansite is the variable of the source. Any valid URL will do. global stream scansite variable initial {"http://www.stilo.com/index.htm"} ;hitcount is the number of times the sought pattern is matched global integer hitcount initial {0} ;defining the function define integer function escan (value string url) as ;local variables within the function ;Request is the HttpRequest that will be built. Response is the ;contents of the page that will be sent from the server. local HttpRequest Request local HttpResponse Response ;Creating the request that will call the web page. HttpRequestSetFromUrl Request from (url) HttpRequestSend Request into Response ;If the website is reached, scan the web page for "OmniMark". do when not(HttpObjectIsInError Request) repeat scan Response {'entity-body'} match "OmniMark" increment hitcount match any again ;If the website cannot be contacted. else output "%n Unable to connect to website %n" done return hitcount ;Program body process output "The Number of times the word OmniMark appears " || "d" % (escan (scansite))
Copyright © Stilo International plc, 1988-2010.