java.lang.ClassCastException:libcore.net.http.HttpURLConnectionImpl无法转换为javax.net.ssl.HttpsURLConnec

编程入门 行业动态 更新时间:2024-10-26 12:30:56
本文介绍了java.lang.ClassCastException:libcore.http.HttpURLConnectionImpl无法转换为javax.ssl.HttpsURLConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一些代码,以通过HTTPS将文件从设备上传到云.

I'm writing a bit of code to upload a file from the device to the cloud over HTTPS.

相关代码段:

HttpsURLConnection conn = null; URL url = new URL(urlstring); conn = (HttpsURLConnection) url.openConnection(); // exception here.

但是强制转换无法编译:

But the cast won't compile:

06-20 15:58:05.311: E/FNF(30286): java.lang.ClassCastException: libcore.http.HttpURLConnectionImpl cannot be cast to javax.ssl.HttpsURLConnection

我发现了类似的问题:使用Java类HttpsURLConnection ,但我没有导入任何内容从太阳包.

I found this similar question: Using java class HttpsURLConnection, but I am not importing anything from the sun package.

我的进口商品:

import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.URL; import android.Uri; import javax.ssl.HttpsURLConnection; import android.util.Log; import edu.mit.media.funf.storage.RemoteFileArchive; import edu.mit.media.funf.util.LogUtil;

我已经为此花了一段时间了,有什么建议吗?

I've been scratching my head about this one for a while now, any suggestions?

推荐答案

方法1: 您的urlString必须以而不是开头,才能将其转换为HttpsURLConnection.

Method 1: Your urlString must begin with and not for you to be able to cast it to a HttpsURLConnection.

方法2: 如果您的urlString以开头,则将HttpsURLConnection更改为HttpURLConnection应该可以

Method 2: if your urlString starts with , changing HttpsURLConnection to HttpURLConnection should work

更多推荐

java.lang.ClassCastException:libcore.net.http.HttpURLConnectionImpl无法转换为javax.ne

本文发布于:2023-10-31 05:14:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545109.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   libcore   net   java   lang

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!