http request header a few common issues related to

http protocol is probably the most commonly used web remoting protocol field, as before soap protocol. As a lightweight and reliable transport protocol based on http protocol service has become almost synonymous with restful, today cited problems in the process http several related use.

  1. Cross-domain
    we are also the most commonly encountered, there are many solutions, such as the introduction of CorsFilter in the Gateway service, or specify the domain name and release all the header.
@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);
    }

Another solution is to adjust the proxy server, such as 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,*';
  1. Chinese header
    HTTP protocol does not support Chinese header! ! !
    Therefore the Chinese want to transfer header information needs to be transcoded, the receiver re-decoded.

Base64.encodeBase64String(origin.getBytes("utf-8"));

  1. header missing
    one problem was encountered, request header There is a parameter request_user_id, certification services interceptors fail to find request.getHeader. Initially suspected apigateway problem, see the apigateway code, find just plain forward, and no re-proxy requests, so there is no problem; ip address to the request retry (a start request is the domain name address), find header value can be obtained, the admission header parameter depends mainly on
    config.addAllowedHeader corsFilter of ( " "), is now configured , which is in addition to all the parameters outside the Chinese should be able to deliver my son.
    Re-sort services link, DNS -nginx-apigateway- goals, nginx is locked to the head. nginx internal setting, and allow all, but there is a limit nginx is underlined parameters will be ignored (pit ah!)
    to adjust the nginx http parameters, open the underline parameters, restart, the problem is resolved.

underscores_in_headers on;

Guess you like

Origin blog.51cto.com/10705830/2442661