怎么在后端设置
Access-Control-Allow-Origin: *
8 回复
Failed to load http://192.168.70.202:8081/user/getInitData?_=1562811870740: Redirect from 'http://192.168.70.202:8081/user/getInitData?_=1562811870740' to 'http://192.168.70.202:8081/login;JSESSIONID=da340b10-0042-47e9-a303-f15524fb9211' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access.
@Filters({@By(type = CrossOriginFilte.class)})
如果有自定义请求头,自己实现替换上面的类
public class MyCrossOriginFilter extends CrossOriginFilter {
// 增加deviceId token 请求头
public MyCrossOriginFilter() {
super();
headers = "Origin, Content-Type, Accept, X-Requested-With, deviceId, token";
}
}
@At
@Ok("raw")
@Filters({@By(type=CrossOriginFilter.class, args={"*", "GET, POST, PUT, DELETE, OPTIONS, PATCH", "Origin, Content-Type, Accept, X-Requested-With", "true"})})
public String getInitData(@Attr("me") int me){
String data = userDao.getInitData(me);
// System.out.println(data);
return data;
}
报错
Access to XMLHttpRequest at 'http://192.168.70.202:8081/user/getInitData?_=1563174382888' from origin 'http://127.0.0.1:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
```
添加回复
请先登陆