gpt4 book ai didi

java - BrowserMob 代理 - WebDriver/错误 : The proxy server is refusing connections

转载 作者:行者123 更新时间:2023-12-01 13:15:51 25 4
gpt4 key购买 nike

我尝试将 BrowserMob Proxy'sWebDriver 一起使用。我使用下一个代码:

public static void main(String[] args) throws Exception {

String strFilePath = "";

// start the proxy
ProxyServer server = new ProxyServer(4455);
server.start();
//captures the moouse movements and navigations
server.setCaptureHeaders(true);
server.setCaptureContent(true);

// get the Selenium proxy object
Proxy proxy = server.seleniumProxy();

// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);

// start the browser up
WebDriver driver = new FirefoxDriver(capabilities);

// create a new HAR with the label "apple.com"
server.newHar("assertselenium.com");

// open yahoo.com
driver.get("http://assertselenium.com");

driver.get("http://assertselenium.com/2012/10/30/transformation-from-manual-tester-to-a-selenium-webdriver-automation-specialist/");

// get the HAR data
Har har = server.getHar();
FileOutputStream fos = new FileOutputStream(strFilePath);
har.writeTo(fos);
server.stop();
driver.quit();

}

我收到了下一个错误:代理服务器拒绝连接:Firefox 配置为使用拒绝连接的代理服务器。

我还尝试使用端口 4455 运行 browsermob-proxy.bat,然后在运行 main 时出现下一个错误>:

java.net.BindException: Address already in use: JVM_Bind

如何使用 BrowserMob 代理?

最佳答案

用于声明代理的代码似乎是正确的。对于 BindException,很明显有东西已经在使用端口 4455。您可以检查它(在 Windows 计算机上,从内存写入):

netstat -ano | find "4455"

在Linux中使用lsof -i:4455来获取PID并杀死它。无论如何,对于您的代理拒绝连接,请尝试显式设置代理,看看您是否有运气,例如

proxy.setHttpProxy("localhost:4455");
proxy.setSslProxy("localhost:4455");

此外,请确保您使用的是最新版本的 FF 和 BMP。

关于java - BrowserMob 代理 - WebDriver/错误 : The proxy server is refusing connections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22480748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com