我正在使用NodeJS查询远程API。我目前正在使用Axios发出请求,但是如果需要,我愿意使用其他软件包。
使用NodeJS,我向远程API发出请求。
Axios.post("http://remote.api/getCookie")
.then(value => {
console.log(value);
});
API返回许多cookie(可以在规范中以及当我在浏览器中对其进行测试时看到)。如何从Axios返回的值访问这些cookie。
答案 0 :(得分:1)
只需从Set-Cookie
标头中获取它们:
Axios.post("http://<url>").then(response => {
const cookies = response.headers["set-cookie"];
// do whatever you want
}
然后您可以自己解析标头,也可以使用cookie或set-cookie-parser 之类的库