我访问了Java
应用中的特定主机名,我不想将其重定向到其他地方。它使用的是HTTP
而不是HTTPS
。是否可能从外部重定向?我想过检查hosts
上的Windows
文件是否包含可能重定向主机名的条目:
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import java.io.File;
import java.io.IOException;
public class HostsFileChecker
{
public static boolean isPossiblyRedirecting(String hostName) throws IOException
{
if (!SystemUtils.IS_OS_WINDOWS)
{
return false;
}
File hostsFile = new File("C:\\Windows\\System32\\drivers\\etc\\hosts");
String hostsFileContents = FileUtils.readFileToString(hostsFile).toLowerCase();
return hostsFileContents.contains(hostName.toLowerCase());
}
}
是否还有其他东西需要检查,或者这甚至没有意义吗? Java绝对是被欺骗的#34;通过此Windows hosts
文件中的重定向,然后访问我的本地Web服务器:
127.0.0.1 example.com