OCXHttp ASP Component

The OCXHttp ASP component lets you make HTTP requests from any program that can use ActiveX/OLE components. The samples here have been checked against IIS and ASP.

Installation
The installation procedure installs OCXHttp.ocx into the installation directory. Support files (mfc42.dll and msvcrt.dll) are installed into the system32 directory if necessary.

System Requirements
You will need a system that supports 32bit OCX components, and software that can contain an OCX component in order to use the OCXHttp OCX component. WinInet.dll must be installed on your machine in the system32 directory. This normally comes free with Internet Explorer.
If you want to request webpages from ASP, you will need IIS V3 or V4 with ASP installed, or another webserver that supports ASP.

Note that due to a problem with wininet.dll that comes with Internet Explorer 4.01, SLL will not work. Use a version prior to IE4.01 on your server machine, or contact Microsoft for details on when a fix will be available.

File Names

OCXHttp.ocx

The OCXHttp ASP component. Type regsvr32 OCXHttp.ocx at the command line to register on your system. The installation should do this automatically for you.

Syntax

Set Requester = Server.CreateObject("OCXHTTP.OCXHttpCtrl.1")

Parameters

Requester
Specifies the name of the object created by the call to Server.CreateObject.

Registry Entries

None.

Methods/Properties used before a Request Method

SetBasicUsernamePassword

Set the Basic Authentication username and password for this request. Version 1.5 and above. Usage:
SetBasicUsernamePassword user1, password1

FlagReload

Get the data from the wire even if it is locally cached: Requester.FlagReload=1 to turn on (default is 0 - off)

FlagDontCache

Do not cache the data, either locally or in any gateways. Requester.FlagDontCache=1 to turn on (default is 0 - off)

FlagUseExistingConnect

If possible, reuse the existing connections to the server for new requests instead of creating a new session for each connection request. Requester.FlagUseExistingConnect=1 to turn on (default is 0 - off)

Flag

V1.2 and above. General purpose property to get and set flags. existingSettings = Requester.flag will retrieve the current flag settings. Requester.flag = nNewFlag will do "flags |= nNewFlag" to set the specified flag, eg
Requester.flag = INTERNET_FLAG_NO_COOKIES
Requester.flag = INTERNET_FLAG_RELOAD

UserAgent

Set the user agent - this is the name of the browser that the server will think the request is made by. Requester.UserAgent="Mozilla/2.0 (compatible; MSIE 3.02; Update a; Windows NT)" (default is "Flicks Software's OCXHttp Component")

Timeout

Sets the timeout in milliseconds. Requester.Timeout =200000 (default and minimum is 60000)

FollowRedirects

V1.2 and above. Set to true for OCXHttp to follow redirects individually. Set to false (the default) and the underlying system will follow redirects as a single group.
When set to true, the HTTP_QUERY_FILE_URL value (which can be retrieved after the request has been made), will contain the end URL, or final destination URL. Otherwise and by default HTTP_QUERY_FILE_URL will contain the original (pre-redirect) URL.
Regardless of the setting of this property, the final destination contents will be returned with the Content or ContentToFile methods.

SetHeader

Sets any request header, including Accept, User-Agent, Content-type etc.

Request Methods

GET

Makes a GET request .

POST

Makes a POST request .

HEAD

Makes a HEAD request .

Methods/Properties used after a Request Method

Content

Returns the content of the request as a string. Note that binary data (eg gif's, jpg's) cannot be returned by this method.

ContentToFile

Outputs the content of the request to the specified file. The OCX host program must have permission to access this file. Binary (images, pdf files etc) or text data are all OK.

QueryInfo

Returns information associated with the request, such as content-type, cookies and headers.

QueryInfoEx

Returns information associated with the request, such as content-type, cookies and headers, handling multiple headers with the same name.

Bonus Methods

CombineURL

V1.2 and above. Combines a base and relative URL into a single URL

ASP Example

The following makes a GET request from ASP.
Note the evaluation version includes a comprehensive example using all methods.

<% 
Set OCXHttp = Server.CreateObject("OCXHTTP.OCXHttpCtrl.1") 
%>
<HTML>
<HEAD>
<TITLE>OCXHttp Simple Example</TITLE>
</HEAD>
<CENTER>
<H2>
OCXHttp Simple Example
</H2>
</CENTER>
<%
result = OCXHttp.GET("http://www.flicks.com/scripts/debug.asp")
If  "" = result Then %>
<P>
File has been retrieved
<H2>
<font color=blue>
Content is:
</font>
</H2>
<HR>
<%
response.Write(OCXHttp.Content)
%>
<HR>
<H2>
<font color=blue>
End of Content
</font>
</H2>
<P>
<% Else %>
<P>
File has not been retrieved, error message is
<H2><%= result %></H2>
<% End If %>
<P>
</FONT>
</BODY>
</HTML>


By Flicks Software