7

在此处输入图像描述

在此处输入图像描述

我正在尝试构建我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);
});  
4

2 回答 2

28

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

在此处输入图像描述 单击代码(在保存按钮下方)> 搜索“Axios”> NodeJS - Axios

postman code gen 现在支持 axios

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

于 2018-12-07T10:17:58.833 回答
0

2022 更新

  1. 单击</>右侧导航栏中的图标

在此处输入图像描述

  1. 从下拉列表中选择 Axios

在此处输入图像描述

于 2022-03-02T21:19:36.267 回答