I am unable to set headers via axios e.g. content-type as application/json. There is no exception thrown by axios but the request gets a "415 Unsupported Media Type" response in browser. Any clues where I am erring?
Following is the code -
I tried 2 approaches.
Approach 1 -
import axios from 'axios';
axios.defaults.headers.common['Content-Type'] = 'application/json';
axios.get(url).then(
response => this.loadData(response)).catch(
(error) => this.showError(error));
Approach 2 -
let config = {
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json"
}
};
axios.get(url, config).then(
response => this.loadData(response)).catch(
(error) => this.showError(error));