Im using axios on my react app to send a delete request, I need to send an id list as payload but it returns "415 Unsupported Media Type".
Here's my code:
const deviceData = ["31234"];
axios.delete(url, { data: deviceData }).then(res => {
if (res.status === 200) {
const pagination = { ...this.state.pagination };
this.setState({
loading: false,
data: res.data.data.devices,
pagination
});
}
});
Im using axios on my react app to send a delete request, I need to send an id list as payload but it returns "415 Unsupported Media Type".
Here's my code:
const deviceData = ["31234"];
axios.delete(url, { data: deviceData }).then(res => {
if (res.status === 200) {
const pagination = { ...this.state.pagination };
this.setState({
loading: false,
data: res.data.data.devices,
pagination
});
}
});
Share
Improve this question
edited Oct 4, 2019 at 9:37
Joshua
3,1763 gold badges26 silver badges40 bronze badges
asked Oct 4, 2019 at 9:29
SNoVSNoV
971 gold badge2 silver badges11 bronze badges
4
- the problem only with delete method ? – Rio A.P Commented Oct 4, 2019 at 9:56
- @RapSherlock Yes – SNoV Commented Oct 4, 2019 at 10:49
- 1 can you try to debug your request in back-end ? – Rio A.P Commented Oct 4, 2019 at 10:56
- @RapSherlock request is tested in postman and its working. – SNoV Commented Oct 4, 2019 at 14:11
1 Answer
Reset to default 17axiox.delete
does support a request body. It accepts two parameters: url
and optional config
. You can use config.data
to set the response body as follows:
axios.delete(url, { data: { foo: "bar" } });
See here to more information: https://github.com/axios/axios/issues/897#issuecomment-343715381
Or you can try to set header with: 'Content-Type': 'application/json; charset=utf-8'
const deviceData = ["31234"];
axios.delete(url,
{ headers:{'Content-Type': 'application/json; charset=utf-8'} },
{ data: { deviceData: deviceData } }).then(res => {
if (res.status === 200) {
const pagination = { ...this.state.pagination };
this.setState({
loading: false,
data: res.data.data.devices,
pagination
});
}
});