HTTP Basic Auth via URL in Firefox does not work?

后端 未结 8 2123
悲&欢浪女
悲&欢浪女 2020-11-30 02:18

I know that normally you can login to sites that require HTTP basic authentication with Selenium by passing the username and password in the URL, e.g.:

sele         


        
8条回答
  •  天命终不由人
    2020-11-30 02:51

    You could try to manipulate the headers directly like this:

    First when you start, you have to enable Selenium ti manipulate headers:

    selenium.start("addCustomRequestHeader=true");
    

    Then you have to use some basic encoding and header manipulation like this:

        String authHeader = "";
        try {
        BASE64Encoder coder = new BASE64Encoder();
        authHeader = coder.encode("developers:Str492ight".getBytes());
        }
        catch (Exception e)
        {
        e.printStackTrace();
        }
        setUpSelenium();
        startSelenium();
        selenium.addCustomRequestHeader("Authorization", "Basic " + authHeader);
        selenium.open("/");
        selenium.waitForPageToLoad("10000");
    

    The space after Basic is necessary. This is how a basic HTTP authentication header looks like..

    Further more you could use some Http Watchers to see if the request contains your auth request.

    Either use Wireshark, or better is Fiddler or Charles Proxy.

    Hope that helped. Gergely.

提交回复
热议问题