asu126 / SpringBootDemo

spring boot
1 stars 0 forks source link

CORS #6

Open asu126 opened 6 years ago

asu126 commented 6 years ago
Failed to load http://localhost:8080/api/user: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access. The response had HTTP status code 405. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
asu126 commented 6 years ago
 return axios(url, {
      method: 'GET',
      mode: 'no-cors',
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Content-Type': 'application/json',
      },
      withCredentials: true,
      credentials: 'same-origin',
    }).then(response => {
    })
asu126 commented 6 years ago
asu126 commented 6 years ago

https://stackoverflow.com/questions/42538827/400-bad-request-error-spring-boot-file-upload-using-jquery-ajax

asu126 commented 6 years ago

http://www.ruanyifeng.com/blog/2016/04/cors.html

reponse:

Access-Control-Allow-Origin: http://localhost:8081
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: close
Content-Type: application/json;charset=UTF-8
Date: Wed, 01 Aug 2018 13:16:29 GMT
Expires: 0
Pragma: no-cache
Transfer-Encoding: chunked
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

request

Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Access-Control-Allow-Origin: http://localhost:8081
Connection: keep-alive
Content-Length: 10
Content-Type: application/x-www-form-urlencoded
Host: localhost:8080
Origin: http://localhost:8081
Referer: http://localhost:8081/users
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
asu126 commented 6 years ago

https://blog.csdn.net/xukai871105/article/details/33800935