request.getHeader("Origin")是什么?
解决方法:
假如:
浏览器地址栏的地址是:http://localhost:4200/#/pages/dashadmin
异步请求后端地址:http://localhost:8080/secure
请求头:
Accept:application/json
Accept-Encoding:gzip, deflate, br
Accept-Language:zh-CN,zh;q=0.9
Authorization:Basic bGJBZG1pbjoxMjM0NTZsYWJvdXI=
Connection:keep-alive
Content-Length:34
Content-Type:application/x-www-form-urlencoded
Host:localhost:8080
Origin:http://localhost:4200
Referer:http://localhost:4200/
User-Agent:Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36
从上面的请求头中可以看到request.getHeader("Origin")的值就是就是http://localhost:4200
request.getHeader("Origin")经常用法就是用来解决浏览器跨域问题
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
指的是只允许http://localhost:4200跨域访问后端服务器。
本文地址:http://www.yayihouse.com/yayishuwu/chapter/1200