Home arrow ASP arrow Page 3 - The Power of the XMLHTTP Library
ASP

The Power of the XMLHTTP Library


XMLHTTP is a set of API's that allows us to send and retrieve data to and from a remote web server using its underlying HTTP protocols and methods. In this article, Mitchell provides us with a basic introduction to the XMLHTTP library, with some examples to get you started.

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 76
December 18, 2001
TABLE OF CONTENTS:
  1. · The Power of the XMLHTTP Library
  2. · XMLHTTP in a nutshell
  3. · Processing the request on the remote server
  4. · The XMLHTTP document headers
  5. · Conclusion

print this article
SEARCH DEVARTICLES

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.
blog comments powered by Disqus
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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials