我正在尝试构建自己的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);
});
答案 0 :(得分:2)
您可以使用Postman中的代码生成功能。
点击“代码”(位于“保存”按钮下方)>从语言下拉列表中选择“ JavaScript”> Jquery AJAX
然后,您可以仅提取所需的数据并将其粘贴到axios中。 例如。网址,标头和其他所需数据。
邮递员中用于生成代码的文档:https://learning.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets/