我正在编写一些代码,以通过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
发布评论