问题描述
我需要使用 BMP 进行响应/请求分析(使用 selenium)。
在本地,一切正常,但是当我尝试在服务器上执行时,出现错误:
我使用多个变体来创建代理:
private void startProxyServer(){
browserProxySniffing.startProxyServer(browserProxySniffing.IP_FOR_PROXY);
browserMobProxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT);
browserMobProxy.newHar();
}
class browserProxySniffing{
.......
public static void startProxyServer(String address) {
IP_FOR_PROXY = address;
if (browserMobProxy.isstarted()) {
browserMobProxy.stop();
}
try {
browserMobProxy.start(9090,Inet4Address.getByName(address));//variant 1 (172.17.0.2 ip using)
browserMobProxy.start(9090);//---variant 2 (the 0.0.0.0 ip addres created)
browserMobProxy.start(9090,Inet4Address.getByName(address));//variant 3 (localhost ip using - works fine on the local mashine)
useExclusivePort = browserMobProxy.getPort();
} catch (Exception e) {
e.printstacktrace();
throw new RuntimeException(e.getMessage());
}
}
}
我按以下方式设置功能:
startProxyServer(IP_FOR_PROXY);
HashMap<String,Object> newCapabilities = browserProxySniffing.getProxyCapabilities();
ChromeOptions options = new ChromeOptions();
options.setCapability("seleniumProtocol","WebDriver");
Proxy seleniumProxy = new Proxy();
seleniumProxy.setHttpProxy(IP_FOR_PROXY + ":" + useExclusivePort)
.setSslProxy(IP_FOR_PROXY + ":" + useExclusivePort);
newCapabilities.put(ChromeOptions.CAPABILITY,options.addArguments("--disable-gpu")
.addArguments("'--ignore-ssl-errors=yes")
.addArguments("--ignore-certificate-errors"));
newCapabilities.put(CapabilityType.PROXY,seleniumProxy);
newCapabilities.put(CapabilityType.ACCEPT_SSL_CERTS,true);
setCapabilities(newCapabilities);
结论
- 代码在本地机器上与 localhost 一起工作正常。所以我相信代码是正确的
- 代码不适用于服务器上的 127.0.0.1
- 代码在服务器早期工作成功(但在重新加载后失败)
- 代码不适用于服务器上的 localhost 和 172.17.0.2
#如何在服务器上使用BMP?
其他信息:
我通过几种方式找到了 172.17.0.2:
b) 使用 /jenkins_home/selenium.xml
c) 与 netstat -an
我还使用了我在 netstat
中找到的所有 ip - 它们都不适合(在 browserMobProxy.start(9090,Inet4Address.getByName(address))
行中失败,但 172.17.0.2 - 成功)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)