解决前端跨域的问题.Access to XMLHttpRequest at http://xxx.xxx from origin 'http://localhost:8000' has been bl


1、前端浏览器报错如下:

Access to XMLHttpRequest at http://xxx.xxx from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

解决前端报错
项目是springboot框架,前后端分离,需要跨域,当前前端可以用JSONP解决,但是java端如何解决呢?

因为是springboot框架,所以好多都可以用注解解决问题,所以就用到了@CrossOrigin,这个是解决跨域问题相当好的一种方法,当然还有写个全局配置类,因为我这里只是个别方法需要跨域,所以不用全局配置。
@CrossOrigin只在方法中配置跨域时,只需要在方法名上加上这一注解就行吗,如果是通用所有的ip访问,就再设置(origins = “*”,maxAge = 3600),当然也可以细化具体的ip。

@CrossOrigin(origins = “*”,maxAge = 3600)
@GetMapping("/getinfos")
public ResponseEntity getInfos() {
return ResponseEntity.ok(userService.getInfos());
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 解决本地浏览器运行项目时的跨域问题-Access to XMLHttpRequest at"xxx/xxx" from origin 'null' has been blocked by CORS policy Access to XMLHttpRequest at 'http://127.0.0.1:8000/XXXXX' from origin 'http://localhost Access to XMLHttpRequest at 'XXX' from origin 'XX' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present o AJAX跨域请求解决方法 报跨域错误:Access to XMLHttpRequest at 'http://localhost:9990/' from origin 'http://IP:Port' has been blocked by CORS policy...more-private address space `local` 后端解决前后端分离跨域问题:Access to XMLHttpRequest at 'http://127.0.0.1:1203/stu/addStu' from origin 'http://localhost:8081' Node 跨域问题 Access to XMLHttpRequest at 'http://localhost:8080/api/user/login' from origin 'http://localhost:808 Access to XMLHttpRequest at 'http://localhost:8090/user/getotp' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. VUE 出现Access to XMLHttpRequest at 'http://192.168.88.228/login/Login?phone=19939306484&password=111' from origin 'http://localhost:8080' has been blocked by CORS policy: The value of the 'Access-Contr ajax post上传数据时,前端出现的跨域权限问题:ccess to XMLHttpRequest at ‘’rom origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok st VUE里面调用高德地图出现跨域和Access to XMLHttpRequest at 'https://restapi.amap.com/v3/geocode/regeo?xx' from origin 'http://xxxx:8080' has been blocked by CORS policy: The value of the 'Access-Contr
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM