[ad_1]
Running the below JavaScript to make a post request to an api but get the error:
Failed to load resource: the server responded with a status of 415 (Unsupported Media Type)
Cors anywhere error is:
Missing required request header. Must specify one of: origin,x-requested-with
I can access the api successfully when I make a get request. And with the post request in python I set the body as a dictionary and the post request is successful. So maybe with JavaScript my data variable object is incorrect as indicated by the 415 error? The api guide advises a body of a key and the values as a list of lists.
let username="username";
let password = 'password';
let data = { 'Locations': [['51.271111446577265','0.15509523254041507']] }
fetch('https://cors-anywhere.herokuapp.com/https://api.conn.example.com/info/v1/c-r/e/m-lc-rk?', {
method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
"Content-Type": "text/plain",
'Authorization': 'Basic ' + btoa(username + ":" + password)
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data));
[ad_2]