reqData({
url: url,
body: req.query.data, //json
timeout: timeout,
method: method,
headers: {
"content-type": "application/json; charset=utf-8"
}
}, function(err, data) {
if(!err) {
res.write(JSON.stringify(data));
res.flush();
res.end();
} else {
var result = {
flag:1,
msg:""
}
res.end(JSON.stringify(result));
}
});
function reqData(options, callback) {
logger.info("request options:", options);
request(options, function(err, response, body) {
if(err) {
logger.error("Error:" + err.message +"\n" + err.stack + "\n", "request & response body:", options, body);
callback(err);
} else {
try {
callback(null, JSON.parse(body));
} catch(err) {
logger.error("Error:" + err.message +"\n" + err.stack + "\n", "request & response body:", options, body);
callback(err);
}
}
});
}
node log keeps reporting error, and error code 400, but the backend actually didn"t receive my request. I don"t know where the reason is
.