1

I'm trying to make an authenticated request using java's URL object. The problem is that I have the @ symbol in my password (changing it is not an option right now), so when java tries the url.getUserInfo() it stops at the @ in the password and screws up my request. I tried escaping it with %40 but from what I see in debug mode it sees it as just %40 and not as an @ character.

Example: http://user:p@ss@stackoverflow.com will take the userinfo as user:p

Schadenfreude
  • 1,522
  • 1
  • 20
  • 41
  • It's a failure in the URL scheme to account for this particular scenario. There's absolutely nothing you can do. – PP. Oct 30 '13 at 12:35

2 Answers2

1

Rather than putting the username and password in the URL, you could register an Authenticator that is able to provide the credentials when required.

Authenticator.setDefault(new Authenticator() {
  protected PasswordAuthentication getPasswordAuthentication() {
    if("stackoverflow.com".equals(getRequestingHost()) {
      return new PasswordAuthentication("user", "p@ss".toCharArray());
    } else {
      return null;
    }
  }
});
Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
0

?os_username=user&os_password=p@ss this is what I found works as an alternative so your request will be authenticated and look like this:
http://stackoverflow.com/stuff?os_username=user&os_password=p@ss

Schadenfreude
  • 1,522
  • 1
  • 20
  • 41