【发布时间】:2017-08-16 11:14:41
【问题描述】:
我需要使用 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 方法是正确的。
任何帮助将不胜感激。
干杯!
【问题讨论】:
标签: web-services meteor http-post