我正在使用async/await(http://stackabuse.com/node-js-async-await-in-es7/並使用bable來轉儲)和請求(https://github.com/request/request)在節點中編寫服務器。我正在嘗試向外部api發出發佈請求並訪問http響應標頭。我只能弄清楚如何訪問我發送的請求。我如何獲得HttpResponse?使用async等待從request.post獲取http響應
下面是代碼
var options = {
url: externalUrl,
form: body
};
try {
var httpResponse = await request.post(options);
console.log(httpResponse.headers.location);
return "post request succeeded!";
} catch (err) {
return done(err, null);
}
'done(err,null)'?在使用promise和async/await時,不應再使用回調。 – Bergi