http協議多是目前web遠程調用領域最經常使用的協議,一如以前的soap協議。做爲輕量級可靠傳輸協議,基於http協議的服務幾乎成了restful的代名詞,今天列舉幾個使用過程當中http 相關的問題。nginx
@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。web
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"));
api
underscores_in_headers on;
跨域