模拟邮递员请求进入 Axios?邮递员、Axios

2023-09-07 10:34:26 作者:今夜星光灿烂つ

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

I'm trying to construct my axios to be able to mimic the postman request but failed. Please help to have a look

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);
});  

推荐答案

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

You can make use of the code-generation feature in Postman.

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

Click on Code (below Save button) > Search for 'Axios' > NodeJS - Axios

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

Docs for code generation in Postman: https://learning.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets/

 
精彩推荐