HOWTO: Use Internet Transfer Control in ASP or in WSH Script

ID: Q188955


The information in this article applies to:
  • Microsoft Visual Basic, Scripting Edition, version 2.0
  • Active Server Pages
  • Microsoft Internet Explorer (Programming)


SUMMARY

Even though it is possible to use the Internet Transfer Control (ITC) on an Active Server Pages (ASP) page to retrieve HTTP URLs, neither the ITC nor WinInet APIs used by the ITC was designed to be used as a server component. Please thoroughly test your application under stress conditions before using it in the production environment.


MORE INFORMATION

IMPORTANT: This article contains information about editing the registry. Before you edit the registry, make sure you understand how to restore the registry if a problem occurs. For information about how to do this, view "Restoring the Registry" Help topic in Regedit.exe or "Restoring a Registry Key" Help topic in Regedt32.exe.

ITC exposes two methods that allow URL downloads: Execute and OpenUrl. It is not possible to use the Execute method in the Windows Script Host script or on an ASP page. VBScript does not support late binding of events; therefore, StateChange notification will never be called.

You can get around this issue by using the OpenUrl method as shown in the following snippet of an ASP page (VBScript is used):


   <%
   Set Inet = Server.CreateObject("InetCtls.Inet.1")
   Inet.RequestTimeOut=20
   Inet.Url = Request.QueryString ("url")
   s = Inet.OpenURL
   response.write(s)
   %> 
Please note the following problems/issues:

  • You must set RequestTimeOut properties when the control is instantiated in the script.


  • When the ITC is used in script, OpenUrl does not work in the following form:

           
          Url = "http://test"
          Inet.OpenUrl (Url, 0) 
    This code causes the ITC to report "Malformed URL" error. Setting the URL property fixes this problem.


  • Because of the known problem on the computers with Internet Explorer 4.0 (or Internet Explorer 4.01), ITC on the ASP page may not be able to access HTTPS URLs.


  • If the code snippet listed above is used to download HTML text with HREF or IMG tags, then only the absolute URL will work. This means that if the ITC retrieves the following page, the Browser invoking this ASP script with the ITC will only show image2.jpg:
    
          <HTML>
          [ASCII 133]
          This is image 1: <IMG SRC="/image1.jpg"> <hr>
          This is image 2: <IMG SRC="http://server/image2.jpg">
          [ASCII 133]
          </HTML> 


  • By default the ITC uses the default connection information such as connection type and proxy name specified in the registry location: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ Internet Settings


This registry location is not available from ASP scripts; therefore, the ITC will not be able to retrieve proxy information. This situation may be remedied as follows.

Following are the methods for using the ITC with the Proxy setting on the ASP page.

Recommended Method:

Setting proxy properties for the ITC on the ASP page as follows:



   Inet.AccessType = 2
   Inet.Proxy = "http://proxy:80"
 
Not Recommended Method:

By modifying the registry hive of the default user.

WARNING: Using the Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. Use the Registry Editor at your own risk.

For information about how to edit the registry, view "Changing Keys And Values" Help topic in Registry Editor (Regedit.exe) or "Add and Delete Information in the Registry" and "Edit Registry Data" Help topics in Regedt32.exe. NOTE: You should back up the registry before you edit it. If you are running Windows NT, you should also update your Emergency Repair Disk (ERD).

You can copy relevant Internet connection values from the HKCU to this default location (and make it available to the control created on the ASP page):


   HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet
   Settings 


Registry keys governing proxy settings described in Internet Client SDK are ProxyEnable, ProxyServer, and ProxyOverride. They are also available at the following Web site:

http://msdn.microsoft.com/workshop/default.asp


Note that anonymous ASP requests are handled in the security context of the anonymous Internet user - IUSR_COMPUTER_NAME by default. Make sure to add security permissions for this user to access the above mentioned registry keys. You can do this by going to the Security menu option of the Registry Editor (regedt32.exe).


REFERENCES

Microsoft Internet Transfer Control Help Microsoft Internet Client SDK

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Leon Braginski, Microsoft Corporation.

Additional query words: ASP ITC MSINET OpenUrl kbInternet kbASP kbWinInet

Keywords : kbWinInet
Version : WINDOWS:2.0; winnt:
Platform : WINDOWS winnt
Issue type : kbhowto


Last Reviewed: September 30, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.