【问题标题】:Unable to perfrom http basic auth using Browsermob proxy无法使用 Browsermob 代理执行 http 基本身份验证
【发布时间】:2018-06-09 14:27:09
【问题描述】:

我正在尝试使用 Browsermob 代理来实现跨不同浏览器的基本 http 身份验证。但是遇到问题,尝试在 Browsermob 的 GITHUB 页面上搜索解决方案,但没有找到太多帮助。

这是我实现身份验证的代码:

    // start the proxy
    BrowserMobProxy proxy = new BrowserMobProxyServer();
    proxy.start();

    proxy.autoAuthorization("", "username", "password", AuthType.BASIC);

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

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

如果我在 chrome 上运行上述代码,那么它仍然会要求身份验证。错误控制台中什么也没有出现。

System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + config.getChromeDriverPath());
WebDriver driver = new ChromeDriver(capabilities);

如果我在firefox上运行上面的代码,那么它会给出错误

您的连接不安全。

System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + config.getChromeDriverPath());
WebDriver driver = new ChromeDriver(capabilities);

并且在控制台中出现以下错误:

FAILED CONFIGURATION: @BeforeClass launchBrowser
org.openqa.selenium.WebDriverException: 
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'USER', ip: '192.168.43.57', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: false, browserName: firefox, browserVersion: 60.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 8180, moz:profile: C:\Users\USER\AppDat..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 6.3, proxy: Proxy(manual, http=tarun:49..., rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 6b53fdb7-78fe-44cb-a3b9-2592494ae7a5

什么不正确?

【问题讨论】:

标签: selenium selenium-webdriver http-authentication browsermob-proxy


【解决方案1】:
proxy.autoAuthorization("", "guest", "guest", AuthType.BASIC);

此功能不起作用。

改用这个:

String encodedCreadentials = "Basic " + (Base64.getEncoder().encodeToString("login:password".getBytes()));
proxy.addHeader("Authorization", encodedCreadentials);

【讨论】:

    猜你喜欢
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-24
    • 2021-10-10
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    相关资源
    最近更新 更多