How do I read params sent to .aspx from JavaScript with XMLHTTPRequest?

Posted on 2005-04-19
Last Modified: 2010-04-16
In the client side I'm doing this:

                 var this.rsSyncObject = null;
            if (window.XMLHttpRequest){
                  this.rsSyncObject = new XMLHttpRequest();
            else if (window.ActiveXObject) {
                  this.rsSyncObject = new ActiveXObject('Microsoft.XMLHTTP');

       "POST", "ThePage.aspx", false);      
                 this.rsResult = this.rsSyncObject.responseText;

And it loads the page and waits for an answer ok, but how do I read the params I sent in the send() function from "ThePage.aspx"?
Question by:mak730
    LVL 2

    Expert Comment

    Use the Request.Form collection - e.g:

    string param1 = Request.Form["param1"];

    LVL 2

    Accepted Solution

    Actually, looking again, you have a strange format for the post data. If you use the standard URL encoding - e.g:

    param1=1&param2=2 etc. (including encoding special URL chars)

    then the Request.Form collection should be populated. Othrewise, you will need to read the Request.InputStream into a strign and split that manually.

    Author Comment

    ok, Request.Form doesn't work at all, but the Request.InputStream does, in fact here is a little code to do the job:

                      private Hashtable GetHTTPParams(){
                      //Create a Stream object.
                      Stream str = Request.InputStream;
                      //Find number of bytes in stream and read.
                      int strLen = Convert.ToInt32(str.Length);                  
                      byte [] buff = new byte[strLen];
                      str.Read(buff, 0, strLen);
                      //Convert byte array to a text string.
                      string s = "";
                      for(int i=0; i<strLen; i++)
                            s += Convert.ToChar(buff[i]);

                      //Convert string into a hashtable
                      Hashtable ht = new Hashtable();
                      string []data = s.Split('&');
                      s = "";
                      for(int i=0; i < data.Length; i++){
                            s = data[i];
                            if (s != ""){                              
                                  string []elem = s.Split('=');
                                  ht.Add(elem[0], elem[1]);
                      return ht;                  
    LVL 2

    Expert Comment

    Glad you got it sorted, though the Request.Form method should work. Possibly need to set the ContentType of the Request to:



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now