javascript - Postman 和带有 superagent 的简单 Http 请求之间的区别

标签 javascript node.js postman http-status-code-301 superagent

我想知道使用 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/

相关文章:

javascript - 获取两个 Date 对象之间的持续时间(以小时和分钟为单位) - JavaScript

javascript - 用于匹配两个其他字符串之间的字符串的正则表达式

node.js - 管道流到 graphicsmagick/imagemagick 子进程

node.js - 禁用 Mongoose 架构中的插件

api - 在 Postman 中为 Azure 通知中心创建注册

javascript - 在 Postman 中将数组推送到环境变量

java - AWS 使用 uploadUrl 时将元数据添加到文件内容

javascript - meteor 内容不显示

javascript - 在 Angular 组件中创建 Angular 服务时,如何为其设置自定义构造函数参数?

node.js - 将流对象转换为字符串