1

  axios.get(url, {
    headers: {
      'Content-Type': 'application/json',
    }
  })
    .then(response => {
      console.log('response',response);
    })
    .catch((error) => {
      console.log('error ' + error);
    });

I tried to set the header " 'Content-Type': 'application/json'"

to solve this problem, it works fine on my postman, but I get 415 on my browser and axios

request in React.

Is it possible to solve this issue on my frontend?

Allyssa
  • 53
  • 1
  • 9
  • 1
    Share postman CURL call? What you do in PostMan should be easily replicable in React. Are you sure you dont have auth or need to pass some params to get data back? – Paul M Aug 07 '20 at 20:28
  • it's same, Content-Type in headers and also key and value on my Params – Allyssa Aug 07 '20 at 20:32
  • anything wrong with my headers format? – Allyssa Aug 07 '20 at 20:32
  • https://stackoverflow.com/a/16693884/4830080 It means that the Content-Type HTTP header should be set only for PUT and POST requests. Seems like you should only specify Content-Type if type === post OR put... Try without the content-type? – Paul M Aug 07 '20 at 20:34
  • Possibly related: https://stackoverflow.com/questions/58375880/why-it-shows-statuscode-415-error-in-axios-get-method – Paul M Aug 07 '20 at 20:46
  • axios({ method: 'get', url: 'URL', responseType: 'application/json', data:{ //your data } }) – Paul M Aug 07 '20 at 20:47

0 Answers0