跨域 服务预检 服务器响应问题

今天使用axios 跨域post时遇到问题

axios.post("url",{'data':"1"}).then(function(res){
  ...
})

request header:明明使用了post

Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Access-Control-Request-Headers: content-type
Access-Control-Request-Method: POST
Connection: keep-alive
Host: localhost:81
Origin: http://localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36

general:实际使用了OPTIONS 操作!

Request URL: http://localhost:81/v1/login/signup
Request Method: OPTIONS
Status Code: 200 OK
Remote Address: 127.0.0.1:81
Referrer Policy: no-referrer-when-downgrade

浏览器还给我报:说服务器没有允许你用 这个头“Access-Control-Request-Headers:content-type” 需要加 "Access-Control-Allow-Headers:content-type"

Failed to load http://localhost:81/v1/login/signup: Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

当时十脸懵逼 跨域不是服务器只要有这些就ok了么?

Access-Control-Allow-Method

Access-Control-Allow-Origin

后来看了下:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Access_control_CORS

猜你喜欢

转载自www.cnblogs.com/zjhblogs/p/9151143.html