I'm trying to fetch data from a Node.JS API via Axios. The API only accepts requests with content-type "application/json" and GET HTTP Method. If the content-type is not "application/json", an error message will be sent back.
I've tested the API with Postman and other HTTP libraries and everything works perfectly fine.
However, when I try to make a request via Axios:
export const getPrivateInstance = axios.create({
baseURL: API_URL,
timeout: 25000,
withCredentials: true
})
getPrivateInstance({
method: 'get',
url: "/getData",
data: JSON.stringify({
projectId: projectID
}),
headers: {
"Content-Type": 'application/json',
}
})
the Content-Type is ignored when specifying GET as the HTTP Method. However, if I change the http method to POST in the axios config and API, it works. But with GET, the content-type is ignored by Axios.
How can one make a GET Request where the content-type is not ignored by Axios?