有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java Selenium FirefoxDriver忽略给定的代理设置

我希望浏览器显示代理值,但它显示了我的实际IP。知道为什么吗

'''

FirefoxOptions options = new FirefoxOptions();
options.addPreference("network.proxy.type", 1);
options.addPreference("network.proxy.https", "151.253.165.70");
options.addPreference("network.proxy.https_port", 8080);
options.addPreference("network.proxy.https_remote_dns", true);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.whatismyip.com");

'''


共 (1) 个答案

  1. # 1 楼答案

    您可以使用firefoxprofile或options。为Https使用的代理添加SSL。 选项。addPreference(“network.proxy.ssl”、“151.253.165.70”); 选项。addPreference(“network.proxy.ssl_port”,8080)

    FirefoxOptions options = new FirefoxOptions();
    options.addPreference("network.proxy.type", 1);
    options.addPreference("network.proxy.https", "151.253.165.70");
    options.addPreference("network.proxy.https_port", 8080);
    options.addPreference("network.proxy.https_remote_dns", true);
    
    options.addPreference("network.proxy.ssl", "151.253.165.70");
    options.addPreference("network.proxy.ssl_port", 8080);
    
    WebDriver driver = new FirefoxDriver(options);
    driver.get("https://www.whatismyip.com");
    

    如果您使用的是个人资料

        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", "151.253.165.70");
        profile.setPreference("network.proxy.http_port", 8080);
        profile.setPreference("network.proxy.https", "151.253.165.70");  
        profile.setPreference("network.proxy.https_port", 8080); 
        profile.setPreference("network.proxy.ssl", "151.253.165.70");
        profile.setPreference("network.proxy.ssl_port", 8080);
        profile.setPreference("network.proxy.https_remote_dns", true);