title: Download https image with Indy for Delphi
body: <p>I've seen quite a few posts on how to download an http image to a memory stream, but I'm having trouble grabbing an https image.</p>
  
  <p>I hoped it would be as easy as dropping an SSL handler in but I keep getting the following error:</p>
  
  <blockquote>
    <p>Error connecting with SSL. error:14094410:SSL reourtines:SSL3_READ_BYTES:sslv3 alert handshake failure.</p>
  </blockquote>
  
  <p>The example site I've been using I think uses SSLv3.</p>
  
  <p><a href="https://apod.nasa.gov/apod/image/1702/NGC1316_MazlinKellerMenaker1024d.jpg" rel="nofollow noreferrer">https://apod.nasa.gov/apod/image/1702/NGC1316_MazlinKellerMenaker1024d.jpg</a></p>
  
  <p>Annoyingly the JSON actually returns an http node, but it gets redirected to the https version</p>
  
  <p><a href="https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY" rel="nofollow noreferrer">https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY</a></p>
  
  <pre class="lang-json prettyprint-override"><code>{
    "copyright": "Steve Mazlin",
    "date": "2017-02-02",
    "explanation": "An example of violence on a cosmic scale, enormous elliptical galaxy NGC 1316 lies about 75 million light-years away toward Fornax, the southern constellation of the Furnace. Investigating the startling sight, astronomers suspect the giant galaxy of colliding with smaller neighbor NGC 1317 seen just above, causing far flung loops and shells of stars. Light from their close encounter would have reached Earth some 100 million years ago. In the deep, sharp image, the central regions of NGC 1316 and NGC 1317 appear separated by over 100,000 light-years. Complex dust lanes visible within also indicate that NGC 1316 is itself the result of a merger of galaxies in the distant past. Found on the outskirts of the Fornax galaxy cluster, NGC 1316 is known as Fornax A. One of the visually brightest of the Fornax cluster galaxies it is one of the strongest and largest radio sources with radio emission extending well beyond this telescopic field-of-view, over several degrees on the sky.  Participate: Take an Aesthetics &amp; Astronomy Survey",
    "hdurl": "http://apod.nasa.gov/apod/image/1702/NGC1316_MazlinKellerMenaker.jpg",
    "media_type": "image",
    "service_version": "v1",
    "title": "NGC 1316: After Galaxies Collide",
    "url": "http://apod.nasa.gov/apod/image/1702/NGC1316_MazlinKellerMenaker1024d.jpg"
  }
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Side note: I have tried changing the SSL version to both <code>sslvTLSv1_1</code> and <code>sslvTLSv1_2</code> but no luck.</p>
  
  <pre><code>function TUrlImageReader.ReadImage: TMemoryStream;
  var
    ImgMS: TMemoryStream;
    ImgHTTP: TIdHTTP;
    SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
  begin
    ImgMS := TMemoryStream.Create;
    SSLHandler:=TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    ImgHTTP:=TIdHTTP.Create(nil);
    ImgHTTP.IOHandler:=SSLHandler;
    SSLHandler.SSLOptions.Method:=sslvSSLv3;
    try
      try
        ImgHTTP.Get(FURL, ImgMS);
      except
        on E: EIdHTTPProtocolException do
          ImgMS.Clear;
      end;
    finally
      ImgHTTP.Free;
      SSLHandler.Free;
    end;
    ImgMS.Position := 0;
    Result := ImgMS;
  end;
  </code></pre>