Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
Get a server Error 415 when trying to access API using JavaScript

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));
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda