Internet service

Use the Internet service to:

Hyperlinking to a URL

You call the Internet service’s HyperLinkToURL function to start the default browser with a specified URL.

StepsTo hyperlink to a URL:

  1. Declare an instance or global variable of type Inet:

    Inet  iinet_base
    
  2. Create the Internet service by calling the GetContextService function:

    THIS.GetContextService("Inet", iinet_base)
    
  3. Call the HyperLinkToURL function, passing the URL of the page to display when the browser starts:

    iinet_base.HyperlinkToURL  &
    
       ("http://www.sybase.com")
    

Getting a URL

You call the Internet service’s GetURL function to perform an HTTP Get, returning raw HTML for a specified URL. This function returns the raw HTML using the InternetResult object.

StepsTo perform an HTTP Get:

  1. Declare an instance or global variable of type Inet. Also declare an instance or global variable using the descendent InternetResult object as the datatype (n_ir_msgbox in this example):

    Inet  iinet_base
    
    n_ir_msgbox  iir_msgbox
    
  2. Create the Internet service by calling the GetContextService function:

    THIS.GetContextService("Internet", iinet_base)
    
  3. Create an instance of the descendent InternetResult object:

    iir_msgbox = CREATE n_ir_msgbox
    
  4. Call the GetURL function, passing the URL of the page to be returned and a reference to the instance of the descendent InternetResult object:

    iinet_base.GetURL  &
    
       ("http://www.sybase.com", iir_msgbox)
    

    When the GetURL function completes, it calls the InternetData function defined in the descendent InternetResult object, passing the HTML for the specified URL.

Posting to a URL

You call the Internet service’s PostURL function to perform an HTTP Post, sending data to a CGI, ISAPI, or NSAPI program. This function returns the raw HTML using the InternetResult object.

StepsTo perform an HTTP Post:

  1. Declare an instance or global variable of type Inet. Also declare an instance or global variable using the descendent InternetResult object as the datatype (n_ir_msgbox in this example):

    Inet  iinet_base
    
    n_ir_msgbox  iir_msgbox
    
  2. Create the Internet service by calling the GetContextService function:

    THIS.GetContextService("Internet", iinet_base)
    
  3. Create an instance of the descendent InternetResult object:

    iir_msgbox = CREATE n_ir_msgbox
    
  4. Establish the arguments to the PostURL function:

    Blob    lblb_args
    
    String  ls_headers
    
    String  ls_url
    
    Long    ll_length
    
    ls_url = "http://coltrane.sybase.com/"
    
    ls_url += "cgi-bin/pbcgi80.exe/"
    
    ls_url += "myapp/n_cst_html/f_test?"
    
    lblb_args = Blob("")
    
    ll_length = Len(lblb_args)
    
    ls_headers = "Content-Length: "  &
       + String(ll_length) + "~n~n"
    
  5. Call the PostURL function, passing the URL of the routine to be executed, the arguments, the header, an optional server port specification, and a reference to the instance of the descendent InternetResult object:

    iinet_base.PostURL  &
       (ls_url, lblb_args, ls_headers, 8080, iir_msgbox)
    

    When the PostURL function completes, it calls the InternetData function defined in the descendent InternetResult object, passing the HTML returned by the specified routine.

Using the InternetResult object

The GetURL and PostURL functions both receive data in an InternetResult object. This object acts as a buffer, receiving and caching the asynchronous data as it is returned by means of the Internet. When all data is received, the InternetResult object calls its InternetData function, which you override to process the data as appropriate.

NoteImplement in descendants of InternetResult You implement this feature by creating standard class user objects of type InternetResult. In each of these descendent user objects, define an InternetData function to process the passed HTML as appropriate.

StepsTo implement a descendent InternetResult object:

  1. Create a standard class user object of type InternetResult.

  2. Declare a new user object function as follows:

  3. Add code to the InternetData function that processes the returned HTML as appropriate. This example simply displays the HTML in a MessageBox:

    MessageBox("Returned HTML", &
       String(data, EncodingANSI!))
    
    Return 1