Mock Postman request into Axios?

本小妞迷上赌 提交于 2020-03-25 15:51:40

问题


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

回答1:


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

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

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.

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



来源:https://stackoverflow.com/questions/53667206/mock-postman-request-into-axios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!