![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|||||||||||
|
Introduction
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 OmniMark 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.
;Copyright 1999 OmniMark Technologies Corporation. All rights reserved.
;
;This is a simple HTTP client written using the HTTP library.
;It will call the OmniMark Technologies web page, scan the contents
;for the word "OmniMark", and count the number of times it occurs.
;
;Command line: omnimark -s -of "ocount.txt"
;Declaring the function libraries:
;The HTTP library depends on the I/O Protocol library and the
;TCP/IP library, and both of these must be included in the order
;they appear here.
;Name and location of the I/O Protocol library file
declare function-library "omioprot"
;I/O Protocol function and constant declarations
include "omioprot.xin"
;Name and location of the TCP/IP library file
declare function-library "omtcp"
;TCP/IP function and constant declarations
include "omtcp.xin"
;HTTP function and constant declarations
include "omhttp.xin"
;scansite is the variable of the source. Any valid URL will do.
global stream scansite variable initial {"http://www.omnimark.com"}
;hitcount is the number of times the sought pattern is matched
global counter hitcount initial {0}
;defining the function
define counter function escan (value stream 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 key ('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))
| ---- |