Retrieving HTTP header information using Network Component

Introduction

Network Component provides an easy-to-use development interface to a variety of IP protocols. By using Network Component, you can very easily create or enhance applications with network features.

Network Component features the following: ICMP, HTTP and HTTPs with support for proxy servers and secure web sites, Telnet, NTP time protocol, RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, Sockets, WOL (Wake-On-LAN), and more.

HTTP Get and HTTP Post can be well integrated into ASP environments. This document describes how the Network Component Http object can be integrated into ASP projects.

The most important functions of the Http object are:

HTTP Headers

When sending an HTTP request to a webserver, the webserver first responds with an HTTP header, followed by the HTML data. This header can contain information about the webserver, client, cookies or proxy information. These values can be retrieved using the 'ReadHeader' method of the Http interface.

The following lines of code demonstrate how to read some header values:

Option Explicit

Dim objHttp

Set objHttp = CreateObject ( "ActiveXperts.Http" )

objHttp.Connect "https://www.activexperts.com"

If ( objHttp.LastError <> 0 ) Then
  WScript.Echo "Failed to load website: ERROR #" & objHttp.LastError & " (" & objHttp.GetErrorDescription ( objHttp.LastError )
  WScript.Quit
End If

WScript.Echo objHttp.ReadHeader ( 37 )

objHttp.Disconnect

The samples connects to the webserver 'www.activexperts.com' and retrieves the server software version. You can find an overview of all HTTP headers and the associated ID's to be used in the 'ReadHeader' method below.

HTTP Header ID's

Accept24List of MIME types supported by the client
Accept-Charset25List of charsets supported by the client
Accept-Encoding26List of encodings supported by the client
Age48The amount of time since the document was generated by the server
Authorization28Authorization credentials request
Content-Description4Description of the content
Content-Encoding29Indicates what additional content codings have been applied to the content
Content-Id3Content identification
Content-Length5Length of the content that follows
Content-Location51Location of the content
Content-MD552MD5 Digest of the content
Content-Type1Content-Type of the document
Cookie44Cookie send by the client, ifthe client has received a cookie from this website before
Date9Date and time the content was generated on the webserver
Etag54Entity tag, used when the content is available on multiple locations
Host55Internet host and port number of the resource being requested
If-Modified-Since32Last time the content has been modified
Location33The current URL
Proxy-Authenticate41Authentication scheme returned by the proxy
Proxy-Authorization61Header that is used to identify the user to a proxy that requires authentication
Range62Can be used to download only a part of the content
Raw-Headers21All header returned by the server, separated by 0 bytes
Raw-Headers-CRLF22All headers returned by the server, separated by carriagereturn - linefeed bytes
Referer35URL of the page that linked to the current page
Request-Method45Request verb that was used, GET or POST
Retry-After36Time returned by the server, the estimated time to generate the response.
Server37Returns the name and version of the server software
Set-Cookie43Cookie received from the server
Status-Code19Status code returned by the server
Status-Text20Additional response text returned by the server
Transfer-Encoding63Indicates the type of transformation that has been applied on the content to transfer it to the client
User-Agent39Name and version of the client software
Version18HTTP Version of the current session (HTTP 1.0 or HTTP 1.1)
Via66Intermediate protocols used between the client and server, set when a proxy server is used
Warning67Additional information about the last request
WWW-Authenticate40Authetication schemes supported by the server