Send and receive Array as GET/POST using querystring

Posted by Vanwaril on Stack Overflow See other posts from Stack Overflow or by Vanwaril
Published on 2011-01-03T17:30:48Z Indexed on 2011/01/03 17:54 UTC
Read the original article Hit count: 218

I've got the following code, but it doesn't seem to work:

var post_req = {
    array: [
        [ {
            param1: 'something',
            param2: 123
        } ],
        [ ],
        [ ],
        [ {
            param2: 'something',
            param4: 1234,
            param1: 'hello'
        } ]
    ]
};
var data_send = querystring.stringify(post_req);

var request = client.request('POST', '/', headers);
request.end(data_send);

and

if( req.method == 'POST' ) {
    req.addListener('data', function(chunk)
    {
        POST = querystring.parse(chunk);
        console.log(POST);
    }
}

I end up with 5 sub-arrays, corresponding to the 5 parameters in the objects but with extra '][' characters in their names:

{ array: 
   [ { '][param1': 'something' }
   , { '][param2': '123' }
   , { '][param2': 'something' }
   , { '][param4': '1234' }
   , { '][param1': 'hello' }
   ]
}

© Stack Overflow or respective owner

Related posts about node.js

Related posts about request.querystring