I am trying to post an associative array to another Node.js server, internaly to my server:
First server does a POST request like this with Request:
var request = require('request');
request.post('http://localhost:8084/',{ json: {"isposted": {"ok":"val"}}});
Second server's result is this:
{ '{"isposted":{"ok":"val"}}': '' }
Instead of:
{"isposted":{"ok":"val"}}
Server's (2nd) source code to parse the data is this:
var http = require('http');
var qs = require('qs');
var processRequest = function(req,callback) {
var body='';
req.on('data', function(data) { body+=data; });
req.on('end', function() { callback(qs.parse(body)); });
}
var server2 = http.createServer(function(req, res) {
processRequest(req,function(data){
try
{
data=JSON.parse(data.jsonData);
}
catch(e)
{
data=data;
}
console.log(data);
});
});
}in it, and I've no idea whererequestis coming from. Presumably you are requiring some module, but which one and where is the code for it? It's hard to help you if you don't create a proper test case. (I haven't even looked at the server half of this yet)