使用http.post meteor发送json文件,然后通过http.get获取它

时间:2017-08-16 11:14:42

标签: web-services meteor http-post

我需要使用http.post将json格式数据发送到url。写了下面的代码来测试本地

 var postData = {
"channelName" : "Number Theory1",
"startDate" : "2017-07-22T06:29:35.681Z",
"endDate" : "2017-08-22T06:29:35.681Z"
}
HTTP.call('POST', 'http://localhost:3000', {
   data: postData 
 }, (error, result) => {
 if (error) {
   console.log('we are getting this error:' + error);
 } else {
    console.log('POstres : ' + result);
 }
 }); 
function extractProcessData(data){
   console.log('function called! : ' + data);     ##data here should be var processData but it prints undefined
}
function confirmDataReceived(data) {
  HTTP.get('http://localhost:3000', function(err, res){
  // confirmation error
  if(err){
    console.log('error ' + err);
  }
  // confirmation success and process data
  else{
    console.log('data : ' + data + res)    ## data here prints as undefined whereas according to me, it should contain thevar postData ##
    extractProcessData(data) //call function to process data
  }
});
}
var postRoutes = Picker.filter(Meteor.bindEnvironment(function(req, res) {
 if (req.method == "POST"){
   console.log('req : ' + req.method + " " + req.body)
   confirmDataReceived(req.body);
 }
 return true;
 // return req.method == "POST";
}));;;

它不起作用。我想问题是http.post数据语法。这是通过http.post发送数据的正确方法吗?我希望我的http.get方法通过picker函数是正确的。

任何帮助都将不胜感激。

干杯!

1 个答案:

答案 0 :(得分:0)

docExpansion: "none"