function demo(request,response){
request.getScheme() is returning http instead of returning https.
System.out.println(""+request.getScheme());
}
输出:http
--上面的函数演示是从 main 方法调用的,但它打印 http 而不是在互联网服务器上工作时应该打印 https。
最佳答案
如果您的服务器在代理服务器后面运行,请确保设置了代理 header :
proxy_set_header X-Forwarded-Proto $scheme;
然后要获得正确的方案
,您可以使用 springframework 的类:
HttpRequest httpRequest = new ServletServerHttpRequest(request); //request is HttpServletRequest
UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
String scheme = uriComponents.getScheme(); // http/https
关于java - request.getScheme() 正在返回 http 而不是在 java 中返回 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25911469/