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
- Move the dll to a directory like: C:\Program Files\XStandard\Bin\.
- Open a command prompt and
cd
to the directory where the dll is located. - Type regsvr32 XHTTP.dll or on 64-bit OS type C:\Windows\SysWOW64\regsvr32.exe XHTTP.dll
- 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.
Uninstall Instructions
- Open a command prompt and
cd
to the directory where the dll is located. - 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.
<%
Dim objHTTP
Set objHTTP = Server.CreateObject("XStandard.HTTP")
objHTTP.AddRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
objHTTP.Get "http://xstandard.com"
If objHTTP.ResponseCode = 200 Then
Response.Write "Web site is up and running!"
Else
Response.Write "Web site is down!!!"
End If
Set objHTTP = Nothing
%>
This example shows how to get data from a remote server and save it to a file
<%
Dim objHTTP
Set objHTTP = Server.CreateObject("XStandard.HTTP")
objHTTP.Get "http://xstandard.com/images/logo.gif"
objHTTP.SaveResponseToFile "C:\Temp\logo.gif"
Set objHTTP = Nothing
%>
This example shows how to get binary data (an image) from a remote server and display it to a Web browser
<%
Dim objHTTP
Set objHTTP = Server.CreateObject("XStandard.HTTP")
objHTTP.Get "http://xstandard.com/images/logo.gif"
Response.BinaryWrite objHTTP.ResponseSafeArray
Set objHTTP = Nothing
%>
Send raw data via HTTP POST to a remote server
<%
Dim objHTTP
Set objHTTP = Server.CreateObject("XStandard.HTTP")
objHTTP.Post "http://server/page.asp", "Hello World!"
Set objHTTP = Nothing
%>
To receive the data, on the remote server, use the following code:
<%
Dim objBuffer
Set objBuffer = Server.CreateObject("XStandard.Buffer")
objBuffer.Write Request.BinaryRead(Request.TotalBytes)
objBuffer.SaveAs "C:\Temp\message.txt"
Set objBA = Nothing
%>
Send Form Data To Remote Server
This example shows how to send form data via HTTP POST to a remote server.
<%
Dim objHTTP
Set objHTTP = Server.CreateObject("XStandard.HTTP")
objHTTP.AddRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.Post "http://server/page.asp", "username=John+Smith&password=hello"
Set objHTTP = Nothing
%>
To receive the data, on the remote server, use the following code:
<%
Dim varKey
For Each varKey In Request.Form
Response.Write varKey & " = " & Request.Form(varKey).Item & "<br />"
Next
%>
Extract hyperlinks from a Web page
This example requires MSXML 4 parser.
<%
Dim objHTTP, objDoc, objNode
Set objDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")
objDoc.Async = False
Set objHTTP = Server.CreateObject("XStandard.HTTP")
objHTTP.AddRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
objHTTP.Get "http://xstandard.com"
If objDoc.LoadXML(objHTTP.ResponseAsXML) Then
For Each objNode In objDoc.SelectNodes("//a[string(@href) != '']")
Response.Write "<div>" & objNode.Attributes.GetNamedItem("href").Text & "</div>
Next
Else
Response.Write "Cannot parse response."
End If
Set objHTTP = Nothing
Set objDoc = Nothing
Set objNode = Nothing
%>