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 ""
    ;scansite is the variable of the source. Any valid URL will do.
    global stream scansite variable initial {""}
    ;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)
    ;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
      ;If the website cannot be contacted. 
        output "%n Unable to connect to website %n"
      return hitcount
    ;Program body 
      output "The Number of times the word OmniMark appears " 
          || "d" % (escan (scansite))