标签:拦截器 byte code 传输协议 传递 认证 梳理 methods post
http协议可能是目前web远程调用领域最常用的协议,一如之前的soap协议。作为轻量级可靠传输协议,基于http协议的服务几乎成了restful的代名词,今天列举几个使用过程中http 相关的问题。@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("HEAD");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
config.addAllowedMethod("POST");
config.addAllowedMethod("DELETE");
config.addAllowedMethod("PATCH");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
另一种解决办法是调整代理服务器如nginx。
add_header ‘Access-Control-Allow-Origin‘ ‘$http_origin‘;
add_header ‘Access-Control-Allow-Origin‘ ‘*‘;
add_header ‘Access-Control-Allow-Credentials‘ ‘true‘;
add_header ‘Access-Control-Allow-Methods‘ ‘GET, PUT, POST, DELETE, OPTIONS‘;
add_header ‘Access-Control-Allow-Headers‘ ‘Content-Type,*‘;
Base64.encodeBase64String(origin.getBytes("utf-8"));
underscores_in_headers on;
标签:拦截器 byte code 传输协议 传递 认证 梳理 methods post
原文地址:https://blog.51cto.com/10705830/2442661