ASP
  Home arrow ASP arrow Page 3 - The Power of the XMLHTTP Library
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  
Moblin 
JMSL Numerical Library 
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 / 55
    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
     
     
    ADVERTISEMENT


    The Power of the XMLHTTP Library - Processing the request on the remote server


    (Page 3 of 5 )

    Once a client has submitted a request to a remote server, that server is in control of processing the request and providing meaningful data, which can then be returned to the client. To demonstrate this, lets create two ASP pages: The first will act as the client. The second will process the client’s request and return a string of data.

    Our first page will use the “GET” HTTP method, as well as one name/value pair tacked onto the end of the URL. The name/value pair “fName=Mitchell” contains my first name. The second page will use this name/value pair to return my complete name to the client, in the form of XML. The client page is named client.asp and its code looks like this:

    <%

    Response.ContentType = "text/xml"

    dim objXMLHTTP

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



    objXMLHTTP.Open "GET", "http://localhost/server.asp?fName=John", false

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

    objXMLHTTP.Send



    Response.Write objXMLHTTP.ResponseText



    %>


    The second page, server.asp which will extract the name/value pair, fName and return my complete name as a string, looks like this:

    <%

    if Request.ServerVariables("HTTP_METHOD") = "GET" then



    dim fName

    fName = Request.QueryString("fName")



    Response.Write "<Name_Details>"

    Response.Write "<TheName>"



    Select Case fName

    Case "Mitchell"

    Response.Write fName & " Harper"

    Case "John"

    Response.Write fName & " Doe"

    Case "Harry"

    Response.Write fName & " Potter"

    Case Else

    Response.Write "[Unknown]"

    End Select

    Response.Write "</TheName>"

    Response.Write "</Name_Details>"



    end if

    %>


    The server.asp script starts of by checking if the HTTP request method is set to “GET”. If it is, then we extract the value of the fName name/value pair from the query string. Next, we output the start of our XML document, simply using a case statement to determine which name is being requested. You can change the name in client.asp to “John”, “Harry” or anything else you like to see the different results.

    Here is the XML returned from the server.asp page when the client.asp page is ran in my browser with fName=Mitchell:

    The XML returned from the server.asp page

    Our server.asp page doesn’t use any fancy techniques to return the XML to the client.asp page: it uses the same Response.Write method that is available through ASP. The pages buffer (which is created using the Response.Write method) is returned to the client.asp page as the response data.

    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 3 hosted by Hostway