JAVA联调接口跨域解决办法

JAVA联调接口跨域解决办法

JAVA联调接口跨域解决办法
第一种代码:
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,HttpStatus.SC_OK, "OK");

response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
如果以上无法返回提交后的结果数据,可以改成一下方式,把response通过spring注入进来,其他response的header无需修改,同上:
@Autowired
private HttpServletResponse response;
        
04-29 21:39