“ java.lang.UnsupportedOperationException:尚不支持。”
您看过这段代码片段了吗?
@Override public Result authenticate(HttpExchange he) {throw new UnsupportedOperationException('Not supported yet.'); }
正是这种情况会在您每次尝试进行身份验证时引发上述异常。
因此,在我看来,解决身份验证问题的方法非常简单:实施此方法。
解决方法我正在尝试做的是:
我正在尝试使用Java连接到[使用https]的Web Portal。我已经编写了使用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());}@Overridepublic Result authenticate(HttpExchange he) { throw new UnsupportedOperationException('Not supported yet.');} } public static void main(String[] args) {// TODO code application logic hereTrustManager[] 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());} }}
第二次Try中引发了异常“java.lang.UnsupportedOperationException:不支持”。我的方法正确吗?如果没有,还有其他选择吗?
当我在Web浏览器中打开页面时,我得到登录页面;一旦提供了凭据,就会显示Web门户
有人可以建议如何访问Webportal并提供我的凭据并检查身份验证是否成功吗?任何示例代码片段都将对您有所帮助。
相关文章:
1. html5和Flash对抗是什么情况?2. 【小白问题】这行python命令行程序是什么意思?3. python - 如何在dataframe中删除某行当某列值为nan时?4. node.js - win7下用nodejs使用gm出错5. python - 如何用pandas处理分钟数据变成小时线?6. javascript 开发百度地图7. 网页爬虫 - python爬虫,需要爬取的数据没在网页源代码中,怎么处理?8. python小白 问关于递归的问题9. python socket 如何接收tcp/ip byte 格式的数据?10. python - 如何用django运行真实的服务器的网址
