节点,BodyParser 错误 json
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')
我在 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')