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)安全超文本传输协议

这两者是相互对应的。

相关文章:

  • 2021-08-14
  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-12-27
  • 2021-06-24
  • 2021-08-03
  • 2021-05-30
相关资源
相似解决方案