Main page
Features, common information
Main principles

  Examples
HTTP connection
Sending email
Low level access

  Download

  Registration

  Methods & properties



Http connection examples

Retrieving text document and document information from Web site

This code retrieves HTML document from specified URL and checks for errors
Set tcpip=CreateObject("SHOTIP.Connection")
Set http=tcpip.http

url="http://hostname.domain.com/filename.htm
' Retrieve document
res=http.FetchData(url)
if res=0 then
  ' There are no communication errors, check HTTP status code
  if http.StatusCode=200 then
    ' Get document content as a string into 'text' variable
    text=http.Convert(2)
    ' Retrieve document last modification date
    dd=http.LastModified
    ' Retrieve real document length
    realsize=http.Length
    ' Retrieve declared document length sent by server
    declaredsize=http("Content-length")
    ' Retrieve server type
    server=http("Server")
  else
    ' There were Http errors (file not found, etc.)
    ' The StatusCode property contains error code
    ' The StatusString property contains error description
    end if
else
  ' There were communication errors
  ' The 'res' variable contains error code
end if

Retrieving binary document from Web site

This code retrieves Jpeg image from specified URL, error checkings are omitted
Set tcpip=CreateObject("SHOTIP.Connection")
Set http=tcpip.http

url="http://hostname.domain.com/filename.jpg
' Retrieve document
res=http.FetchData(url)
' Get document content as a binary safearray
bdata=http.Convert()
' Write safearray content into file
tcpip.WriteFile bdata,0,UBound(bdata)+1,"c:\path\to\file.jpg"

Post Web form content to Web site

This code post Html form data to specified URL, as if they came from Web browser
Set tcpip=CreateObject("SHOTIP.Connection")
Set http=tcpip.http

url="http://hostname.domain.com/cgi-bin/action.pl"
' Setting form input fields
http.AddHtmlFormInput "firstname","John"
http.AddHtmlFormInput "age",25
http.AddHtmlFormInput "sex","M"
' Retrieve document
res=http.FetchData(url,"POST")
' Form data are sent
' Get returned document content as a text
doc=http.Convert(2)

Retrieve redirection to other URL

This code checks if server response is a redirection to other URL
Set tcpip=CreateObject("SHOTIP.Connection")
Set http=tcpip.http

url="http://hostname.domain.com/script.asp"
' Retrieve document
res=http.FetchData(url)
if http.StatusCode = 301 or http.StatusCode = 302 then
  redirUrl = http("Location")
end if

 ©2001 Mikhail Tchikalov
 mtchikalov@usa.com