JavaScript
  Home arrow JavaScript arrow Page 4 - Programmatic POST Requests with JavaScript...
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  
Mobile Linux 
App Generation ROI 
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? 
JAVASCRIPT

Programmatic POST Requests with JavaScript: Automated Form Submissions
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 23
    2005-07-20

    Table of Contents:
  • Programmatic POST Requests with JavaScript: Automated Form Submissions
  • Automated POST requests: the basics of a JavaScript-based form emulator
  • Building the form emulator: defining the core functions “getXMLHTTPObject()” and “sendRequest()”
  • Tracking the request’s status: defining the “displayStatus()” function

  • 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


    Programmatic POST Requests with JavaScript: Automated Form Submissions - Tracking the request’s status: defining the “displayStatus()” function


    (Page 4 of 4 )

    Certainly, the program needs to be capable of tracking the status of the current http request. For doing that,  I’ve defined the “displayStatus()” function, useful for tracking the request status. Its code looks like this:

    // function displayStatus

    function displayStatus(){

        // check XMLHttpRequest object status

        if(objhttp.readyState==4){

            // create paragraph elements

            var parStat=document.createElement('p');

            var parText=document.createElement('p');

            var parResp=document.createElement('p');

            // assign ID attributes

            parStat.id='status';

            parText.id='text';

            parResp.id='response';

            // append text nodes

            parStat.appendChild(document.createTextNode('Status : '+objhttp.status));

            parText.appendChild(document.createTextNode('Status text : '+objhttp.statusText));

            parResp.appendChild(document.createTextNode('Document code : '+objhttp.responseText));

            // insert <p> elements into document tree

            document.body.appendChild(parStat);

            document.body.appendChild(parText);

            document.body.appendChild(parResp);

        }

    }

    The task that the above function must perform is simply to verify the status of the XMLHttpRequest object, by checking the value of the “readyState” property. Once the request has been completed, the function will append dynamically three regular paragraphs to the document tree, in order to display basic information about the status of the request.

    As you can see, the values for the “status”, “statusText” and “responseText” properties are displayed, useful for tracking the server response. In particular, I’ve defined this function to show information in a rather rough way, but it might be improved by adding a more polished look and feel.

    At this point, I’ve specified generically the complete set of functions that composes the JavaScript program to generate post form submissions. Aside from exposing in detail the core logic of the script, the key functions have been covered, in order to get an accurate idea about how http requests can be handled in the background, as a transparent execution process.

    Certainly, there are a few functions that need to be deeply reviewed yet, to complete the program and make it fully functional. Also, a working example is definitely highly desired, so you can see how a visitor with bad intentions may use this technique for firing attacks, by exploiting the fairly weak structure present in Web forms.

    Wrapping up

    In the next part of the series, I’ll be covering all of the above mentioned topics, by providing you with all of the makings of a functional JavaScript-based form emulator. Since the logic of the program is based on real hacking techniques, I strongly encourage you to pay close attention to the concepts explained here. It never hurts to learn; you can then take what you learned here and translate it into building more robust and safer web applications.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · The second part of the series explains the basics of POST http requests, used widely...
       · Hi,Based on your article, I should be able to retrieve the values sent with the...
       · Hello,Thanks for the comments.About your question, I've not tested...
       · Excellent serie,But, when i try with any compiled page get following error “Acceso...
       · Thank you for the kind comments on my Ajax article. Actually, it’s normal to get...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






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