SunQuest
 
       ASP
  Home arrow ASP arrow Page 2 - The Power of the XMLHTTP Library
IBM developerWorks
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

The Power of the XMLHTTP Library
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 54
    2001-12-18

    Table of Contents:
  • The Power of the XMLHTTP Library
  • XMLHTTP in a nutshell
  • Processing the request on the remote server
  • The XMLHTTP document headers
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    The Power of the XMLHTTP Library - XMLHTTP in a nutshell


    (Page 2 of 5 )

    XMLHTTP can be thought of as an XML-based response/request protocol, which allows us to send text/xml to a remote server. That server processes the request, and in-turn, returns either a text/XML data stream or a binary stream of characters. There are literally an unlimited number of ways that the XMLHTTP library can be used. Here’s a simple ASP example to get you started:

    <html>

    <head>

    <title> XMLHTTP Example </title>

    </head>

    <body bgcolor="#FFFFFF" text="#000000">

    <%

    dim objXMLHTTP

    set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")



    objXMLHTTP.Open "GET", "http://www.devarticles.com/books.php", false

    objXMLHTTP.SetRequestHeader "Content-type", "text/html"

    objXMLHTTP.Send



    %>

    <xmp>

    <%=objXMLHTTP.ResponseText%>

    </xmp>

    </body>

    </html>


    In the example above, we’re creating a new instance of the XMLHTTP library. The XMLHTTP library’s ProgID is Microsoft.XMLHTTP. Next, we call its Open method, which takes three arguments:
    1. Method: The method argument tells the XMLHTTP library which protocol we will be using to communicate with the remote server. The XMLHTTP library is compatible with the HTTP 1.1 protocol.
    2. URL: Tells the XMLHTTP library the location and page of the remote server where all data should be sent. The URL argument can also include name/value pairs, such as http://www.mysite.com/getbook.asp?bookId=345&authorId=953
    3. Async: Tells the XMLHTTP library whether to use asynchronous transfer mode or not. If true, the XMLHTTP library will handle all communication and data transfer in the background, allowing your ASP page to continue to load. We have set it to false, because we want our data available before continuing (AKA synchronous mode).
    There are also two other arguments that the Open method of the XMLHTTP library accepts. These are the username and password, which should be tacked onto the end of any call to the Open method if you’re requesting data that is on a server needing authentication details passed with the transmission. Most of the time, these will not be included.

    The SetRequestHeader method allows us to set the headers that will be passed along with our XML data to the remote web server. Next, we call the Send method, which actually carries out the request on the remote server.

    Because we have chosen to use synchronous transfer methods, our data is available as soon as the Open method is complete. The ResponseText variable contains the resultant response from the remote server as plain text. If we were receiving binary data, we would use the ResponseBody variable. As you can see, we have outputted the resultant text inside of <xmp> and </xmp> tags, which tell the browser to render anything between those tags as text, and not HTML.

    Go ahead and copy the code above into an ASP page on your server. It will retrieve the code behind the devArticles.com recommended reading page. If you remove the <xmp> and </xmp> tags, you will see the HTML rendered version of the text retrieved from the Send method. Yes, the XMLHTTP library has literally contacted the devArticles.com server, retrieved the code behind books.php and stored it in the ResponseText variable of our XMLHTTP object. Pretty neat, ey?

    The XMLHTTP object doesn’t stop there, however. Let’s now see an example where the remote server processes the clients request and returns some sort of meaningful response.

    More ASP Articles
    More By Mitchell Harper


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway