The XHTML WYSIWYG Editor For Desktop & Web Applications

HTTP Component

Overview

Designed for high-performance server environments, this HTTP transfer component can be used to fetch or transfer data from remote servers. Custom HTTP headers can be added such as "User-Agent". Control the number of redirects to follow and get the last URL of a redirect. Clean up response HTML with built-in HTML Tidy for easy parsing as XML. This component can be used in environments that support COM such as Active Server Pages, Windows Scripting Host, Visual Basic, etc.

License
Freeware
Type
32-bit ActiveX DLL
Version
4.1
File Name
XHTTP.dll
Download Package
x-http.zip

Download

Download HTTP Component

Installation Instructions

  1. Move the dll to a directory like: C:\Program Files\XStandard\Bin\.
  2. Open a command prompt and cd to the directory where the dll is located.
  3. Type regsvr32 XHTTP.dll or on 64-bit OS type C:\Windows\SysWOW64\regsvr32.exe XHTTP.dll
  4. Grant "Read & Execute" file permissions on this dll to Everyone.

Note, the command prompt must be "Run as administrator" as shown in the screen shot below.

Context menu for the command prompt showing the option to run as administrator.

Uninstall Instructions

  1. Open a command prompt and cd to the directory where the dll is located.
  2. Type regsvr32 -u XHTTP.dll or on 64-bit OS type C:\Windows\SysWOW64\regsvr32.exe -u XHTTP.dll

Usage from 64-bit OS

Please see instructions for 64-bit OS usage.

API Reference: ProgID: XStandard.HTTP

Property AbsoluteTimeout As Boolean

Set the method to calculate timeout. If True, then obj.TimeOut is total number of milliseconds before the component gives up trying to establish a connection. If False, then obj.TimeOut is the time between receiving data packets from the server.

Sub AddRequestHeader(sName As String, sValue As String)

Add a custom header

Sub ClearRequestHeaders()

Clear all custom headers

Sub Get(sURL As String)

Open HTTP connection using GET method

Function GetResponseHeader(sName As String) As String

Read a single response header

Sub Head(sURL As String)

Open HTTP connection using HEAD method

Property HTTPVersion As String

Protocol version. Default is HTTP/1.0

Property MaxRedirects As Long

Maximum number of redirects to follow. Set 0 for no redirects and -1 for unlimited.

Property Port As Long

(read-only)
Port number for the last connection.

Sub Post(sURL As String, vPostData As Variant)

Open HTTP connection using POST method

Property Proxy As String

Name or IP address of a proxy server

Property ProxyPassword As String

A password if Basic authentication is to be used for the proxy

Property ProxyUser As String

A user name if Basic authentication is to be used for the proxy

Property Redirects As Long

(read-only)
Number of redirects

Property RequestHeaders As String

(read-only)
All request headers

Function ResolveRelativeURL(sBaseURL As String, sRelativeURL As String) As String

Resolve relative URL. This method is used for building a Web crawler. Given a base URL like http://xstandard.com/docs/info.htm and a relative URL like ../contact.htm into http://xstandard.com/contact.htm

Property ResponseAsXML As String
(read-only)

Convert current HTML page to an XML document by using Tidy.

Property ResponseCode As Long

(read-only)
Response code from the last server

Property ResponseContentLength As Long

(read-only)
Number of bytes of returning data

Property ResponseContentType As String

(read-only)
Content type of the returned data

Property ResponseCookiesAsXML As String

(read-only)
Response cookies in XML format

Property ResponseHeaders As String

(read-only)
All response headers

Property ResponseSafeArray As Variant

(read-only)
Response data in binary form

Property ResponseStatus As String

(read-only)
Status line received from the last server. Example 'HTTP/1.0 200 OK'

Property ResponseString As String

(read-only)
Response data in text form

Sub SaveResponseToFile(sPath As String)

Save response data from last server to file

Property TimeOut As Long

A time out for the connection. Default is 30000 ms.

Property URL As String

(read-only)
URL of the last server

Function URLDecode(inStr As String) As String

Decode string by using URL encoding

Function URLEncode(inStr As String) As String

Encode string by using URL encoding

Property Version As String

(read-only)
Product Version

Examples

The examples below are for Active Server Pages. For Windows Scripting Host or Visual Basic, replace Server.CreateObject with CreateObject and replace Resonse.Write with MsgBox.

This example shows how to check the status of a Web site

An HTTP response code number 200 means the Web server sends data back OK.

  1. <%
  2. Dim objHTTP
  3. Set objHTTP = Server.CreateObject("XStandard.HTTP")
  4. objHTTP.AddRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
  5. objHTTP.Get "http://xstandard.com"
  6. If objHTTP.ResponseCode = 200 Then
  7. Response.Write "Web site is up and running!"
  8. Else
  9. Response.Write "Web site is down!!!"
  10. End If
  11. Set objHTTP = Nothing
  12. %>

This example shows how to get data from a remote server and save it to a file

  1. <%
  2. Dim objHTTP
  3. Set objHTTP = Server.CreateObject("XStandard.HTTP")
  4. objHTTP.Get "http://xstandard.com/images/logo.gif"
  5. objHTTP.SaveResponseToFile "C:\Temp\logo.gif"
  6. Set objHTTP = Nothing
  7. %>

This example shows how to get binary data (an image) from a remote server and display it to a Web browser

  1. <%
  2. Dim objHTTP
  3. Set objHTTP = Server.CreateObject("XStandard.HTTP")
  4. objHTTP.Get "http://xstandard.com/images/logo.gif"
  5. Response.BinaryWrite objHTTP.ResponseSafeArray
  6. Set objHTTP = Nothing
  7. %>

Send raw data via HTTP POST to a remote server

  1. <%
  2. Dim objHTTP
  3. Set objHTTP = Server.CreateObject("XStandard.HTTP")
  4. objHTTP.Post "http://server/page.asp", "Hello World!"
  5. Set objHTTP = Nothing
  6. %>

To receive the data, on the remote server, use the following code:

  1. <%
  2. Dim objBuffer
  3. Set objBuffer = Server.CreateObject("XStandard.Buffer")
  4. objBuffer.Write Request.BinaryRead(Request.TotalBytes)
  5. objBuffer.SaveAs "C:\Temp\message.txt"
  6. Set objBA = Nothing
  7. %>

Send Form Data To Remote Server

This example shows how to send form data via HTTP POST to a remote server.

  1. <%
  2. Dim objHTTP
  3. Set objHTTP = Server.CreateObject("XStandard.HTTP")
  4. objHTTP.AddRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  5. objHTTP.Post "http://server/page.asp", "username=John+Smith&password=hello"
  6. Set objHTTP = Nothing
  7. %>

To receive the data, on the remote server, use the following code:

  1. <%
  2. Dim varKey
  3. For Each varKey In Request.Form
  4. Response.Write varKey & " = " & Request.Form(varKey).Item & "<br />"
  5. Next
  6. %>

Extract hyperlinks from a Web page

This example requires MSXML 4 parser.

  1. <%
  2. Dim objHTTP, objDoc, objNode
  3. Set objDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")
  4. objDoc.Async = False
  5. Set objHTTP = Server.CreateObject("XStandard.HTTP")
  6. objHTTP.AddRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
  7. objHTTP.Get "http://xstandard.com"
  8. If objDoc.LoadXML(objHTTP.ResponseAsXML) Then
  9. For Each objNode In objDoc.SelectNodes("//a[string(@href) != '']")
  10. Response.Write "<div>" & objNode.Attributes.GetNamedItem("href").Text & "</div>
  11. Next
  12. Else
  13. Response.Write "Cannot parse response."
  14. End If
  15. Set objHTTP = Nothing
  16. Set objDoc = Nothing
  17. Set objNode = Nothing
  18. %>