您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

sun.net.www.protocol.https.HttpsURLConnectionImpl无法转换为sun.net.www.protocol.http.HttpURLConnection

sun.net.www.protocol.https.HttpsURLConnectionImpl无法转换为sun.net.www.protocol.http.HttpURLConnection

@KarolDowbecki的分析方向正确。

代替sun.net.www.protocol.http.HttpURLConnection; 应该通过以下方式解决

import java.net.HttpURLConnection;

我能够执行您的程序,并产生以下输出

size of all link and images list81
https://makemysushi.com/404#navigation
https://makemysushi.com/
https://makemysushi.com/
https://makemysushi.com/sushi-university
https://makemysushi.com/sushi-recipes
https://makemysushi.com/sushi-essentials
https://makemysushi.com/store
https://www.facebook.com/Makemysushi/
https://www.instagram.com/explore/tags/makemysushi/
https://plus.google.com/+Makemysushi
mailto:info@makemysushi.com   // <-- this href attribute is of MailToURLConnection type raising the java.lang.ClassCastException which can't be casted to HttpURLConnection type
.
.
.
https://makemysushi.com/Sushi-share/contact-us
https://makemysushi.com/Sushi-share/about-us
null
null
null
null
size of activelink list77
https://makemysushi.com/404#navigation----Not Found
https://makemysushi.com/----OK
https://makemysushi.com/----OK
https://makemysushi.com/sushi-university----OK
https://makemysushi.com/sushi-recipes----OK
https://makemysushi.com/sushi-essentials----OK
https://makemysushi.com/store----OK
https://www.facebook.com/Makemysushi/----OK
https://www.instagram.com/explore/tags/makemysushi/----OK
https://plus.google.com/+Makemysushi----OK
Exception in thread "main" java.lang.ClassCastException: sun.net.www.protocol.mailto.MailToURLConnection cannot be cast to java.net.HttpURLConnection
    at demo.TestMakeMySushi.main(TestMakeMySushi.java:48)

列表 包含一个元素:

<a href="mailto:info@makemysushi.com" target="_blank"><i id="social-em" class="fa fa-envelope-square fa-3x social"></i></a>

当您尝试通过 href 属性 **mailto:info@makemysushi.com如下所示** :

HttpURLConnection connection = (HttpURLConnection) new URL(activelist.get(j).getAttribute("href")).openConnection();

无法建立成功的连接,因为 对象无法转换为 对象,并引发

dotnet 2022/1/1 18:20:25 有316人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶