Skip to content Skip to sidebar Skip to footer

Classcastexception With Httpsurlconnection

I try to establisch a HttpsURLConnection with: HttpsURLConnection conn = (HttpsURLConnection) new URL(url).openConnection() but I get an Exception: E/JavaBinder( 901): java.lang.

Solution 1:

The ClassCastException is telling you that the object being returned is not a HttpsUrlConnection. The cast you are doing is inherently unsafe, instead you should something like:

URLConnectionconn=newURL(url).openConnection();
if (conn instanceof HttpsURLConnection) {
  // do stuff
}
else {
  // error?
}

As to the reason its not giving you an Https version, what url are you providing it with? My guess is you are giving it http:.. instead of https:...

Solution 2:

What is the URL? It looks like you are using a plain "http:" scheme URL, but expecting an HTTPS connection.

Post a Comment for "Classcastexception With Httpsurlconnection"