我昨天发布了这个问题:https ://stackoverflow.com/questions/25919099/how-do-i-use-callback-to-solve-authentication-issue
基本上我想等待我的登录请求的响应,然后去签入请求。否则签入请求会给出 401,即身份验证错误。
现在我正在尝试使用诸如 step、wait.for 或 async 之类的库来等待响应。使用 async.series 我正在尝试此代码,但unexpected token function
在function two()
function checkin() {
async.series[(
function one() {
agent1
.post(login-url)
.type('form') // send request in form format
.send({
username: username,
password: password
})
.end(function(err, res) {
console.log("response for login is ", res.statusCode, " ", res.message);
});
}
function two() {
for (var i = 0; i < count; i++) {
if (validatePayment(rows[i].Payment) == true && validateMobile(rows[i].Mobile) == true) {
console.log("inside validation");
agent1
.post(checkin-url)
.send({
phone: rows[0].Mobile,
outlet: outletID
//outlet: "rishi84902bc583c21000004"
})
.end(function(err, res) {
console.log("response for checkins is ", res.statusCode, " ", res.message);
});
)];
}
}
}
// });
}