Node, BodyParser bad json



我在javascript中有这段代码:

var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.post('/test', function (req, res) {
console.log(req.body);
})
var server = app.listen(8080, function () {
})

从 rails 应用程序中,我应该在正文中接收此 json:

 {"content": "some content", "test":"some tests"}

但相反,我收到了这个:

{ '{"content":"some content","test":"some test"}' : ''}

知道我做错了什么吗??

以下是发送 JSON 的方式:

response = JSON.parse RestClient.post("#{test_runner_url}/test", {content: content, test: test}.to_json)

所以答案是:

RestClient.post("#{test_runner_url}/test", {content: content, test: test}, :content_type => 'application/json')

最新更新