Windows Scripting
  Home arrow Windows Scripting arrow Handling Live Web Content in WSH - Part 2
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
WINDOWS SCRIPTING

Handling Live Web Content in WSH - Part 2
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2006-12-19

    Table of Contents:
  • Handling Live Web Content in WSH - Part 2
  • Making the Connection
  • Handling the Response
  • Handling Errors and Exceptions
  • Implementing a Workaround
  • Other Uses for XMLHttpRequest

  • 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


    Handling Live Web Content in WSH - Part 2


    (Page 1 of 6 )

    In part one of this article we began to explore the XMLHttpRequest object and how it could be used to interact with live web content. We focused primarily on reading the contents of a web page (a technique known as “screenscraping”) and parsing that data into our script. This time we are going to take a look at the rest of the methods provided by the XMLHttpObject and how we can use them to send data to a web server for remote form submission.

    You may want to review part one of this article before going any further if you need to refresh your memory. The XMLHttpRequest object is a versatile tool because it’s installed by Internet Explorer (which means that it’s native to every machine on which you run your script). Its simple construct also makes coding this into your scripts as painless as possible.

    We’re going to use the XMLHttpRequest object to submit POST data to a form. In order to do this we’ll need two things. The first is the full URL where we want to send our request. You can find this by looking at the source code for the form.  The URL will be in the action attribute of the <form> html tag. Remember that this may be a relative reference so you may have to include the rest of the URL from your browser’s address bar. I have uploaded a sample form to use when testing this script. It is located at the following URL:

    http://images.devshed.com/af/stories/hlwc2/testform.php

    Next, we need to construct our POST data string.  This is just a string that contains simple data field-value pairs for the form fields that we want to submit.  Each data field is separated from the next by an ampersand (&) just as if we were appending it to a URL. The only difference is that we do not need to encode it, so any special characters are okay.

    Our example uses two form fields: “name” and “address.” It also contains a hidden field named “action” whose value is set to “data” by default. Let’s assume we want to submit the following data in our form:

    Name:    John Doe

    Address: 123 My Street

    With this information, we would construct the following POST data string which I’ve separated across two lines for aesthetic purposes:

    strPostData = “action=data&name=John Doe” _

       & “&address=123 My Street”

    actionURL = “http://images.devshed.com/af/stories/hlwc2/testform.php”

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · After several good discussions and a good response from the first article, I decided...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek