我想知道使用 superagent 的简单 POST 请求和使用 Postman 的 POST 请求有什么区别。 因为我试图废弃一个网站,所以我向 Postman 发出了一个帖子请求,一切正常,我得到了预期的结果。但是当我使用 superagent 进行 POST Http 请求时,我得到了 301 重定向。
有没有办法解决这个问题,得到与 Postman 相同的结果?
预先感谢您的回答。
最佳答案
您应该使用重定向
。简单的例子:
const request = require('superagent');
const url = 'localhost:3000/example';
request
.post(url)
.send({msg: "hello"})
.redirects(1) //Add redirect functionality
.on('redirect', function(res) {
console.log('Redirected');
})
.end(function(err, res){
console.log(res);
})
关于javascript - Postman 和带有 superagent 的简单 Http 请求之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44870053/