问题
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