我有一个试图从特定 HTTPS URL 获取内容的小程序。我使用了以下示例代码:
URL url = new URL(urlLink);
URLConnection urlConn = (URLConnection)url.openConnection(); //https:link
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Accept-Language","en");
urlConn.setAllowUserInteraction(false);
urlConn.setRequestProperty("Content-length",String.valueOf(data.length()));
urlConn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
DataOutputStream out=new DataOutputStream(urlConn.getOutputStream());
out.writeBytes(data);
out.flush();
out.close();
我间歇性地收到以下异常:
*** ServerHelloDone
[read] MD5 and SHA1 hashes: len = 4
0000: 0E 00 00 00 ....
AWT-EventQueue-2, handling exception: java.lang.UnsupportedOperationException
%% Invalidated: [Session-6, SSL_RSA_WITH_RC4_128_MD5]
AWT-EventQueue-2, SEND TLSv1 ALERT: fatal, description = internal_error
AWT-EventQueue-2, WRITE: TLSv1 Alert, length = 2
[Raw write]: length = 7
0000: 15 03 01 00 02 02 50 ......P
AWT-EventQueue-2, called closeSocket()
AWT-EventQueue-2, called close()
AWT-EventQueue-2, called closeInternal(true)
javax.net.ssl.SSLException: java.lang.UnsupportedOperationException
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
.....
Caused by: java.lang.UnsupportedOperationException
at javax.crypto.CipherSpi.engineWrap(CipherSpi.java:870)
at javax.crypto.Cipher.wrap(Cipher.java:2417)
at sun.security.ssl.RSAClientKeyExchange.<init>(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverHelloDone(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
... 33 more
在检查 CipherSpi.engineWrap 实现时,我看到以下内容:
protected byte[] engineWrap(Key key)
throws IllegalBlockSizeException, InvalidKeyException
{
throw new UnsupportedOperationException();
}
好心劝告....