我正在嘗試使用java的URL對象進行已認證的請求。問題是我的密碼中有@
符號(現在不能更改它),所以當java嘗試url.getUserInfo()
時,它會在密碼中停止@
,並將我的請求鎖定。我試着用%40
來轉義它,但從我在調試模式中看到的它只能看到%40
而不是@
字符。轉義密碼中的@字符
例子:http://user:[email protected]@stackoverflow.com
將用戶信息作爲user:p
我正在嘗試使用java的URL對象進行已認證的請求。問題是我的密碼中有@
符號(現在不能更改它),所以當java嘗試url.getUserInfo()
時,它會在密碼中停止@
,並將我的請求鎖定。我試着用%40
來轉義它,但從我在調試模式中看到的它只能看到%40
而不是@
字符。轉義密碼中的@字符
例子:http://user:[email protected]@stackoverflow.com
將用戶信息作爲user:p
而不是將用戶名和密碼,您可以註冊一個Authenticator,在需要時可以提供憑據。
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
if("stackoverflow.com".equals(getRequestingHost()) {
return new PasswordAuthentication("user", "[email protected]".toCharArray());
} else {
return null;
}
}
});
?os_username=user&[email protected]
這是我發現的作品作爲一種替代,以便您的請求將被驗證,並期待這樣的:
http://stackoverflow.com/stuff?os_username=user&[email protected]
這是URL方案中的一個失敗,以說明這種特定情況。你絕對沒有辦法。 –