0

I am trying to create user profile page for my app. I succeed with connecting to Facebook, so i have the user basic profile using userProfile = Profile.getCurrentProfile(); Now i am trying to create a drawable of the user profile picture to put in a image view. For this I created a inputstream to fetch the image(running on asyncTask)

            Bitmap x;
            url =  new URL("https://graph.facebook.com/939344862743414/picture?height=200&width=200");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestProperty("User-agent","Mozilla/4.0");
            connection.setConnectTimeout(100000);
            connection.connect();
            BufferedInputStream buf = new BufferedInputStream(connection.getInputStream());
            x = BitmapFactory.decodeStream(buf);

However no matter what I do,the app failed and crash when it reach the connection.getInputStream(). The error is javax.net.ssl.SSLProtocolException: SSL handshake aborted I couldn't find any help on the web .It doesn't seem as an authorization problem because I can connect to Facebook and fetch data. What I am doing wrong?

Nadav Nagel
  • 313
  • 1
  • 2
  • 8

1 Answers1

0

The issue is created by the url. As the URL contains https which means the web server certificate is issued by a well known CA, so that you can make a secure request. As you are using HttpURLConnection it doesn't support secured URL.

So you can enable the access to secured url (https://..) by using URLConnection in the place of HttpURLConnection. So modify the following line:

HttpURLConnection connection = (HttpURLConnection) url.openConnection();

with this one:

URLConnection connection = (URLConnection) url.openConnection();

Detail information can be found here.

Mohammad Arman
  • 7,020
  • 2
  • 36
  • 50