request.getScheme() is returning http instead of returning https in java

后端 未结 3 1253
太阳男子
太阳男子 2021-02-05 18:05
function demo(request,response){
        request.getScheme() is returning http instead of returning https.
        System.out.println(\"\"+request.getScheme());
}
         


        
3条回答
  •  攒了一身酷
    2021-02-05 18:21

    If your server is running behind a proxy server, make sure your proxy header is set:

    proxy_set_header X-Forwarded-Proto  $scheme;
    

    Then to get the right scheme you can use springframework's classes:

    HttpRequest httpRequest = new ServletServerHttpRequest(request); //request is HttpServletRequest
    UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
    
    String scheme = uriComponents.getScheme(); // http/https
    

提交回复
热议问题