ASP 2.x HTTP Get and HTTP Post Sample Source Code
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: DNS, FTP, HTTP, HTTPs, ICMP Ping, IP-to-Country, MSN, NTP, RSH, SCP, SFTP, SNMP v1/v2c (Get, GetNext, Set), SNMP Traps, SNMP MIB, SSH, TCP, Telnet, TFTP, UDP, Telnet, Wake-On-LAN and more.
Network Component can be well integrated into any development platform that supports ActiveX objects.
The most important functions of the Http object are:
- Connect - connect to the (remote) HTTP web server on port 80 or any alternate port; optionally, use proxy credentials to use a proxy server; optionally, specify a web account and password for password protected web sites
- Disconnect - to diconnect after a connect call;
- ReadData - read all data from a web page;
- WriteData - write data to a web page.
Step 1: Download and install the Network Component
Download Network Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Step 2: Create a new Web Site
First, create a new directory on the IIS Server's file system. This directory will hold the ASP later on.
From the 'Start menu', click on 'Administrative Tools' and click on 'Internet Information Services (IIS) Manager'. Right-click on the 'Web Sites' container and choose 'New->Web Site':
The 'Web Site Creation Wizard' is shown, guiding you thorugh the process of creating a new web site. Provide all necessary information:
- Description - a friendly description of the new site;
- IP / Port / Host Header - choose your preferred way to distinguish between other web sites on the server;
- Path - select the directory that will store the ASP file(s);
- Web Site Access Permissions - in the Web Site Access Permissions dialog, enable 'Read' and 'Run scripts (such as ASP)';
You're now able to write an ASP script to use IP protocols with Network Component.
Step 3: Create the from
First of all we need to create a form in HTML to get the login information for the ftp server. All we actually need is:
- The log-in name.
- The password.
- The server we want to connect to.
- And the directory we're going to list.
In this sample all we're going to do is create a ASP file that is able to list files and directories in a directory. Using Network Component it is easy to create a page that makes you able to upload and to download files.
You can create a form that looks like this:
Appendix: Full source code
<object runat="server" progid="AxNetwork.HttpEx" id="objHttp"> </object> <% ' HTML-CSS layout includes below, no code there! %> <!-- #include file="css/Header.html" --> <!-- #include file="css/Menu.html" --> <% ' A license key is required to unlock this component after the trial period has expired. ' Call 'Activate' with a valid license key as its first parameter. Second parameter determines whether to save the license key permanently ' to the registry (True, so you need to call Activate only once), or not to store the key permanently (False, so you need to call Activate ' every time the component is created). For details, see manual, chapter "Product Activation". ' ' objHttp.Activate "XXXXX-XXXXX-XXXXX", False %> <% Dim numLastError, strLastError, strResponse Set fso = CreateObject("Scripting.FileSystemObject") strLogfile = fso.GetSpecialFolder(2) & "\Http.log" numLastError = 0 strLastError = "" strResponse = "" If( Request( "btnSubmit" ) <> "" ) Then objHttp.LogFile = Request( "txtLogFile" ) ' Optional: set LogFile property for troubleshooting purposes objHttp.WebAccount = Request( "txtWebAccount" ) objHttp.WebPassword = Request( "txtWebPassword" ) strResponse = objHttp.Get( Request( "txtUrl" ) ) numLastError = objHttp.LastError strLastError = numLastError & ": " & objHttp.GetErrorDescription( numLastError ) End If %> <div> <h1>ActiveXperts Network Component ASP Sample - HTTP</h1> <form action="http.asp" method="post"> <h2>Component:</h2> <h3>Module [<% = objHttp.Module %>]; Build [<% = objHttp.Build %>]</h3> <!-- WebSite --> <label for="Website">URL:</label> <p> <span></span> <input style="width: 295px" type="text" name="txtUrl" value="<% If Request( "txtUrl" ) = "" Then%>https://www.activexperts.com/products/<% Else %><% = Request( "txtUrl" ) %><% End If %>"> </p> <!-- Web Account (optional) --> <label for="Website">Web Account (optional):</label> <p> <input type="text" name="txtWebAccount" value="<% If Request( "txtWebAccount" ) = "" Then %><% Else %><% = Request( "txtWebAccount" ) %><% End If %>"> </p> <!-- Web Password (optional) --> <label for="Website">Web Password (optional):</label> <p> <input type="password" name="txtWebPassword" value="<% If Request( "txtWebPassword" ) = "" Then %>""<% Else %><% = Request( "txtWebPassword" ) %><% End If %>"> </p> <!-- Submit Button --> <div></div> <p> <input type="submit" value="Visit web site now" name="btnSubmit"> </p> <!-- Empty Row --> <div></div> <!-- Logfile --> <label for="Logfile">Logfile:</label> <p> <input type="text" id="LogFile" name="txtLogFile" value="<% = strLogfile %>" /> </p> <!-- Result --> <label for="Result">Result:</label> <p> <input type="text" id="Result" name="txtResult" style="font-weight: bold;" value="<% = strLastError %>" /> </p> <!-- Response --> <label for="Result">Response::</label> <p> <textarea name="txtResponse" rows="10" cols="60"><% = strResponse %></textarea> </p> </form> <p> This sample is based on ActiveXperts Network Component, an <a href="https://www.activexperts.com" target="_blank">ActiveXperts Software</a> product.<br /> <a href="default.asp">Back to main page</a> </p> </div><!-- /container --> <% ' HTML-CSS layout include below, no code there! %> <!-- #include file="css/Footer.html" -->
You can download the complete samples here. There are many other working Network Component scripts on our site and shipped with the product.