【发布时间】:2011-06-19 04:20:21
【问题描述】:
我想做什么:
我正在尝试使用 Java 连接到 Web Portal [使用 https]。 我已经编写了使用 Authenticator 类提供用户凭据的代码。当我运行程序时,我得到一个异常:
“java.lang.UnsupportedOperationException:尚不支持”
我已经发布了代码:
public class Main {
public class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getpasswordAuthentication() {
String username = "username";
String password = "password";
// Return the information
return new PasswordAuthentication(username, password.toCharArray());
}
@Override
public Result authenticate(HttpExchange he) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
public static void main(String[] args) {
// TODO code application logic here
TrustManager[] trustClients = new TrustManager[]{
new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
throw new UnsupportedOperationException("Not supported yet.");
}
public X509Certificate[] getAcceptedIssuers() {
return null;
//throw new UnsupportedOperationException("Not supported yet.");
}
}
};
try {
SSLContext sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, trustClients, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());
} catch (Exception e) {
System.out.println("in 1st catch " + e);
}
try {
URL url = new URL("https://someURL.server.com/fmk/jsp/ltpaLogin.jsp");
URLConnection urlconnection = url.openConnection();
System.out.println(urlconnection);
System.out.print(urlconnection.getInputStream().toString());
} catch (Exception e) {
System.out.println("in 2ndcatch " + e.getMessage());
}
}
}
在第二次尝试中引发了异常“java.lang.UnsupportedOperationException:尚不支持”。我的方法是否正确?如果没有,还有其他选择吗?
当我在网络浏览器中打开页面时,我会看到登录页面;一旦我提供了我的凭据,就会显示网络门户
谁能建议如何访问门户网站并提供我的凭据并检查身份验证是否成功? 任何示例代码 sn-ps 都会非常有帮助 提前谢谢..
【问题讨论】: