java.lang.ClassCastException: libcore.net.http.HttpURLConnectionImpl cannot be cast to javax.net.ssl.HttpsURLConnection
1.在虚拟器里运行时老是溢出这个异常,把自己的url从“localhost:(端口号)”改成“10.0.2.2: (端口号)”还是没用;
2.后来Google之,找到问题所在,要把’http’改成‘https’;(s代表security)
源代码:
1: HttpsURLConnection conn = null;
2: URL url = new URL(urlstring);
3: conn = (HttpsURLConnection) url.openConnection(); // exception here.
logcat中爆出的异常是长这样的:
1: 06-20 15:58:05.311: E/FNF(30286): java.lang.ClassCastException: libcore.net.http.HttpURLConnectionImpl cannot be cast to javax.net.ssl.HttpsURLConnection
问题在我的import中:
1: import javax.net.ssl.HttpsURLConnection;
解释:
SSL(Secure Sockets Layer 安全套接层)
HTTPS(Secure Hypertext Transfer Protocol)安全超文本传输协议
这两者是相互对应的。