【问题标题】:Mock Postman request into Axios?模拟邮递员请求进入 Axios?
【发布时间】:2019-05-09 01:59:18
【问题描述】:

我正在尝试构建我的axios 以便能够模仿邮递员的请求,但失败了。请帮忙看看

const ax = axios.create({
  timeout: 30000,
  headers: {
    'content-type': 'application/x-www-form-urlencoded'
  }
});

// Attempt register operation
ax.post('https://url/5bc9ff9628d79b6d274165da/update.json', {
  body: JSON.stringify({
    json: JSON.stringify({ "stat": "Delivered" })
  })
})
.then(({ data }) => {
  console.log('DEBUG::success!!! data::', data);
})
.catch((err) => {
  console.log('DEBUG::err', err);
});  

【问题讨论】:

  • 你也能显示标题截图吗
  • @Goldy:请看一下。剩下的两个密钥将被隐藏,因为它是一些我认为在这个问题中不需要的密钥

标签: reactjs api react-native axios postman


【解决方案1】:

您可以使用 Postman 中的代码生成功能。

单击代码(在保存按钮下方)> 搜索“Axios”> NodeJS - Axios

Postman 代码生成文档:https://learning.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets/

【讨论】:

  • 不知道有这么棒的功能!非常感谢朋友!
猜你喜欢
  • 1970-01-01
  • 2021-09-24
  • 2021-01-14
  • 2020-07-18
  • 2017-12-16
  • 1970-01-01
  • 2019-05-06
  • 2017-06-17
  • 2020-05-22
相关资源
最近更新 更多