我正在尝试做的事情:
我正在尝试使用Java连接到[使用https]的Web Portal.我已经编写了使用Authenticator类提供用户凭据的代码.运行该程序时,出现异常:
I am trying to connect to Web Portal [that uses https]using Java. I have written code for supplying user credentials using Authenticator class.When I run the program I get an Exception:
"java.lang.UnsupportedOperationException:尚不支持"
"java.lang.UnsupportedOperationException: Not supported yet"
我已经发布了代码:
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("someURL.server/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:目前尚不支持".我的方法正确吗?如果没有,还有其他选择吗?
the exception "java.lang.UnsupportedOperationException: Not supported yet"is raised in the 2nd Try.Is my approach correct ? if not is there any alternative to do so ?
在Web浏览器中打开页面时,会显示登录页面;一旦提供凭据,就会显示Web门户
When I open the page in web browser I get the login page;Once I supply my credentials the web portal is displayed
任何人都可以建议如何访问Webportal并提供我的凭据并检查身份验证是否成功吗?任何示例代码片段都将非常有帮助预先感谢..
Can any one please suggest how to hit the webportal and supply my credentials and check the authentication is success or not ? Any sample code snippets will be really helpful Thanks in advance..
推荐答案您看过这段代码片段了吗?
Have you seen this code fragment ?
@Override public Result authenticate(HttpExchange he) { throw new UnsupportedOperationException("Not supported yet."); }恰恰是每次您尝试进行身份验证时都会引发上述异常的人.
It's precisely the one that will throw the aforementionned exception each time you try to authenticate.
因此,在我看来,解决身份验证问题的方法非常简单:实施此方法.
So, to my mind, the solution to your authentication problem is quite simple : implement this method.
更多推荐
"java.lang.UnsupportedOperationException:尚不支持."
发布评论