Meteor iron:路由器在JSON时准备request.body

Meteor iron:路由器在JSON时准备request.body,json,meteor,request,iron-router,Json,Meteor,Request,Iron Router,目前我使用iron:router的restful API解决方案。为此,我使用了.put,.get。。。方法:路由器已经实现 这是我的工作示例: Router.route('/api', {where:'server'}) .put(function(){ var req; req = this.request; console.log(req.body); this.response.end('PUT finished.'); }); 当我执行以下操作时,我将得到预期的

目前我使用iron:router的restful API解决方案。为此,我使用了
.put
.get
。。。方法:路由器已经实现

这是我的工作示例:

Router.route('/api', {where:'server'})
.put(function(){

  var req;
  req = this.request;
  console.log(req.body);

  this.response.end('PUT finished.');

});
当我执行以下操作时,我将得到预期的响应(PUT finished):

但是
console.log(req.body)
返回一个转换为对象的奇怪值

返回值为:

{ 
  '{"name": "timo"}\n' : '' 
}
iron:router似乎试图将主体转换为对象,但没有识别出给定的请求字符串是有效的JSON字符串

我做错了什么?我还没有发现任何有用的东西来准备iron:router,即给定的请求主体仍然是JSON


也许更好的解决方案是不告诉iron:router给定的请求是JSON,而是告诉iron:router它不应该做任何事情,这样我就可以自己转换JSON字符串了

您没有在curl请求中指定内容类型。请尝试以下方法:

curl -XPUT "http://localhost:4000/api " -d'{"name": "timo"}' -H "content-type: application/json"
这对我来说很有用:

I20150522-09:59:08.527(-7)? Request { name: 'timo' }

(没有它也不会)。

好的-谢谢你的提示。但也有可能准备好用户不请求给定的内容类型?直接将数据作为对象使用会很好,用户是否发送内容类型的请求也无所谓。
I20150522-09:59:08.527(-7)? Request { name: 'timo' }