0
我有兩個類:向登錄網站發送http發佈請求? (授權)
public class ProtectedAuthorizer extends Authenticator {
public String authorizeProtectedUrl(String requestingUrl) {
Authenticator.setDefault(new CustomAuthenticator());
StringBuffer sb = null;
try {
URL url = new URL(requestingUrl);
BufferedReader br = new BufferedReader(new InputStreamReader(
url.openStream()));
String in = "";
sb = new StringBuffer();
while ((in = br.readLine()) != null) {
sb.append(in + "\n");
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
}
這是我第二類:
protected PasswordAuthentication getPasswordAuthentication() {
String username = "username";
String password = "password";
String promptString = getRequestingPrompt();
String hostname = getRequestingHost();
InetAddress ipaddr = getRequestingSite();
int port = getRequestingPort();
System.out.println(promptString);
System.out.println(hostname);
System.out.println(ipaddr);
System.out.println(port);
return new PasswordAuthentication(username, password.toCharArray());
}
}
我想對自己授權給這個網站:https://id.ogplanet.com/login.og 但每當我打電話
authorizeProtectedUrl("https://id.ogplanet.com/login.og");
它什麼都不做。我如何使用這兩個類來授權我自己進入登錄頁面? (發送HTTP發佈請求到登錄頁面)。
你在哪裏調用getPasswordAuthentication()? – sachinrahulsourav 2012-03-31 12:00:25
如果我想授權我自己,我不應該這麼稱呼嗎? – ZimZim 2012-03-31 12:16:38