[英]How to call this get api with sending the body using axios?
Hi I can call the the api in the postman like this.嗨,我可以像这样调用邮递员中的 api。
The data return fine in the postman邮递员中的数据返回正常
But when I try to get the api from the axios request the api always give me 500但是当我尝试从 axios 请求中获取 api 时,api 总是给我 500
What am I doing wrong?我究竟做错了什么?
axios
.get('/dwapi/productsapi/GetProductList', {
params: {
group: 'Baby&Kids',
subgroup: '',
subsubgroup: '',
pagesize: '',
pagenum: '4',
minprice: '',
maxprice: '',
brand: '',
size: '',
promotion: '',
bhgexclusive: '',
sortorder: '',
sortby: '',
search: '',
},
})
.then(res => {
console.log(res);
// dispatch({
// type: FETCH_PRODUCT_LIST,
// payload: res.data,
// });
})
.catch(err => {
throw err;
});
axios
.get('/dwapi/productsapi/GetProductList', {
group: 'Baby&Kids',
subgroup: '',
subsubgroup: '',
pagesize: '',
pagenum: '4',
minprice: '',
maxprice: '',
brand: '',
size: '',
promotion: '',
bhgexclusive: '',
sortorder: '',
sortby: '',
search: '',
}
)
.then(res => {
console.log(res);
// dispatch({
// type: FETCH_PRODUCT_LIST,
// payload: res.data,
// });
})
.catch(err => {
throw err;
});
It seems like you want to send your parameters in the body and not the URL parameters, thus you should not be specifying the params
property:似乎您想在正文中发送参数而不是 URL 参数,因此您不应指定
params
属性:
axios
.get('/dwapi/productsapi/GetProductList', {
group: 'Baby&Kids',
subgroup: '',
subsubgroup: '',
pagesize: '',
pagenum: '4',
minprice: '',
maxprice: '',
brand: '',
size: '',
promotion: '',
bhgexclusive: '',
sortorder: '',
sortby: '',
search: '',
})
.then(res => {
console.log(res);
// dispatch({
// type: FETCH_PRODUCT_LIST,
// payload: res.data,
// });
})
.catch(err => {
throw err;
});
In axios, you can try with data
instead of params
.在 axios 中,您可以尝试使用
data
而不是params
。 And let me know what will be the result.并让我知道结果是什么。
axios
.get('/dwapi/productsapi/GetProductList', {
data: {
group: 'Baby&Kids',
subgroup: '',
subsubgroup: '',
pagesize: '',
pagenum: '4',
minprice: '',
maxprice: '',
brand: '',
size: '',
promotion: '',
bhgexclusive: '',
sortorder: '',
sortby: '',
search: '',
},
})
.then(res => {
console.log(res);
// dispatch({
// type: FETCH_PRODUCT_LIST,
// payload: res.data,
// });
})
.catch(err => {
throw err;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.