title: Error downloading images from Facebook Graph API with HTTPS with Android
body: <p>I am not be able to download images with the HTTPS protocol due to a certificate error. This happens a couple of weeks or more, before that, I didn't have any problem.</p>
  
  <p>If I use the HttpCommons Apache library, the error is "the hostname certificate didn't match" and if I use the URL and URLConnection the exception is "the certificate wasn't verified".</p>
  
  <p>I'm desperated because I need to accomplish this to finish my project and all I have tested didn't work.</p>
  
  <p>This is the code with the Apache library:</p>
  
  <pre><code>HttpClient client = new DefaultHttpClient();
  
  HttpGet get = new HttpGet(url);
  
  try
  {
      HttpResponse response = client.execute(get);
      if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
      {
          HttpEntity entity = response.getEntity();
          if (entity != null)
          {
              try
              {
                  byte[] data = EntityUtils.toByteArray(entity);
                  bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                  //bitmap = BitmapFactory.decodeStream(entity.getContent());
              } catch (IOException e)
              {
                  e.printStackTrace();
                  Log.e("FACEBOOKLIBRARY", "Error fetching image from this URL: " + url
                          + "because of the download is corrupted");
                  bitmap = null;
              } finally
              {
                  entity.consumeContent();
              }
          }
      }
      else
      {
          Log.e("FACEBOOKLIBRARY", "Error fetching image from this URL: " + url
                  + " because of the error: " + response.getStatusLine().toString());
          bitmap = null;
      }
  } catch (IOException e)
  {
      e.printStackTrace();
      Log.e("FACEBOOKLIBRARY", "Error fetching image while connecting to this URL: " + url);
      bitmap = null;
  }
  
  return bitmap;
  </code></pre>
  
  <p>And this is the URL code:</p>
  
  <pre><code>try {
      URL u = new URL(url);
      URLConnection connection = u.openConnection();
      InputStream is = connection.getInputStream();
      BufferedInputStream bis = new BufferedInputStream(is);
  
      ByteArrayBuffer baf = new ByteArrayBuffer(50);
      int current = 0;
      while((current = bis.read()) != -1) {
          baf.append(current);
      }
      byte[] byteArray = baf.toByteArray();
      bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
  } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      bitmap = null;
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      bitmap = null;
  }
  </code></pre>