将邮递员请求模拟到Axios? [英] Mock Postman request into Axios?

查看:131
本文介绍了将邮递员请求模拟到Axios?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


推荐答案

您可以在中使用代码生成功能邮递员。

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


单击代码(在保存按钮下方)>从语言下拉菜单中选择 JavaScript> jQuery AJAX

Click on Code (below Save button) > From the language dropdown choose 'JavaScript' > Jquery AJAX

然后,您只需提取数据即可您需要并粘贴到axios中。
例如

Then you can just pick up the data that you need and paste in axios. Eg. the url, headers and other data that is required.

用于在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/

这篇关于将邮递员请求模拟到Axios?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆