API works on POSTMAN, but not on code

0

I am trying to access an API, by postman, it works and returns the json normally, since the code (using VueJS + Axios) does not return, from the CROSS error, how can this? and does the axios return normally?

let headers = {
        'Authorization': 'AUTENTICACAO BASIC',
        'Content-Type': 'application/json'
      }

axios.post('URL DA API', body, headers)
      .then(response => {
        console.log(response)
      })
      .catch(error => {
        console.log(error)
      })

In body , I'm sending the necessary data to the return .. Remembering that in postman, returns the json correctly. Return is error 401

    
asked by anonymous 05.06.2017 / 15:20

2 answers

3

You need to enable CORS on the side in the API you are trying to use.

HTTP access control (CORS)

    
05.06.2017 / 15:55
0

You can specify urls that can access your API, using annotation @CrossOrigin (url) this is certainly the reason for the error

    
17.06.2018 / 02:43