axios跨域问题

时间:2020-05-01

参考:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Access_control_CORS

报错

Access to XMLHttpRequest at 'http://mysmarty.com/home/index/register' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

解决办法

服务端程序header设置允许content-type

Access-Control-Allow-Credentials: 1
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Origin: http://localhost:3000
Connection: keep-alive
Content-Type: text/json;charset=utf-8
Date: Thu, 26 Mar 2020 12:14:39 GMT
Server: nginx/1.16.0
Transfer-Encoding: chunked
X-Powered-By: PHP/7.3.7