I'm trying to send data in a body using the GET method. It's working fine when i try to run using POSTMAN/cURL/Python but it's not working using AXIOS(ReactJS).
cURL:
curl -X GET \
http://127.0.0.1:8000/xyz/xyz/ayx-api/ \
-H 'Authorization: Token 980e4e673a9cfb4c99cb35313f65a446aa44faf7' \
-H 'Content-Type: application/json' \
-H 'Postman-Token: 1ee27393-b4b0-446a-b613-bd319e02e3c8' \
-H 'cache-control: no-cache' \
-d '{"dataId": 1, "date": "2018-03-01", "days": 9 }'
this curl working fine
Using Axios:
import axios from 'axios';
const baseUrl = process.env.BACKEND_SERVER_URL;
export const fetchDataObjects = async() => {
const header = {
'Content-Type': 'application/json',
'Authorization': `Token ${localStorage.token}`,
}
const data ={"dataId": 1, "date": "2018-03-01", "days": 9 }
const res= await axios.get(`${baseUrl}/ayx-api/`,{data:JSON.stringify(data)}, {headers: header})
// above line need to helop
return res.data;
}
How can i send data in body using axios in get method?
Thanks in advance.