swirl Guide to OmniMark 5   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
     
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 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.

  ;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 integer hitcount initial {0}

  ;defining the function
  define integer 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 {'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)) 

       
----

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ OMX ] [ OMX ] [ ERRORS ]

Generated: August 11, 2000 at 3:06:21 pm
If you have any comments about this section of the documentation, send email to docerrors@omnimark.com

Copyright © OmniMark Technologies Corporation, 1988-2000.