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

Posted on 2005-04-19
Medium Priority
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');

                 this.rsSyncObject.open("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
  • 3

Expert Comment

ID: 13823137
Use the Request.Form collection - e.g:

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


Accepted Solution

SThorogood earned 600 total points
ID: 13823152
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

ID: 13824856
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;                  

Expert Comment

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



Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

840 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