1

I'm using Vue and Axios to build a SPA frontend. When server send a response with code 400 in CROS. Browser's console log:

(2) POST http://dev.sportx.one/api/token/ 400 (Bad Request) **This line logged twice**
Failed to load http://dev.sportx.one/api/token/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 400.
Error: Network Error
    at e.exports (spread.js:25)
    at XMLHttpRequest.l.onerror (spread.js:25)

How I send request:

api.request({
 url: '/api/token/',
  method: 'post',
  data: {
    email: '972372527@qq.com',
    password: 'aaaaaaaA'
  }
}).catch(err=>{console.log(err)})

Browser's network inspector shows 2 requests(OPTIONS and POST) has been sent. The both of them are working as expected.

How ever if server send a 20X response without any error catches. Everything is fine.

I try the same code in a new html file and only load axios's script file. Got the same errors.

Emile Bergeron
  • 14,368
  • 4
  • 66
  • 111
lei li
  • 930
  • 7
  • 19

2 Answers2

0

You need set 'Access-Control-Allow-Origin': '*'

Alex
  • 2,383
  • 19
  • 23
0

Preflight request shouldn't response 400 error.

lei li
  • 930
  • 7
  • 19