Link to home
Start Free TrialLog in
Avatar of maxoss
maxoss

asked on

Delphi + HTTPS (indy)

Hi experts,
I try to get an image from the web to show in my form when I press Button1. The following code perfectly works but only for images in HTTP pages. The image I try to get is situated on an HTTPS page. Although it is on HTTPS, the access doesn't require a login. You can try to paste the URL in your browser and it will show the image. Why isn't it working the same in Delphi?

I'm using this in Delphi 7.
By the way, it's not because it's a PNG, I added a TPNGImage component in uses and PNG images that are in http (not https) show in my form.

Thank you for your valuable time.
procedure TForm1.Button1Click(Sender: TObject);
var
  IdHTTP1:Tidhttp;
  MyStreamt:TMemoryStream;
  jp:TPNGImage;
 
begin
 
  MyStreamt:=TMemoryStream.Create;
  Try
    IdHTTP1:=Tidhttp.Create(nil);
    Try
      IdHTTP1.Get('https://www.clusif.asso.fr/images/clusif/flags/en16.png',Mystreamt);
    except
      ShowMessage('Error Getting File');
      Exit;
    End;
    Mystreamt.Seek(0, soFromBeginning);
    jp:=TPNGImage.Create;
    Try
      jp.LoadFromStream(MyStreamt);
      Image1.Picture.Assign(jp);
    Finally
      jp.free;
    End;
  Finally
    IdHTTP1.Free;
    MyStreamt.Free;
  End;
end;

Open in new window

Avatar of 2266180
2266180
Flag of United States of America image

you need to setup a ssl io handler for that.
you should read the following page :http://www.indyproject.org/Sockets/SSL.EN.aspx (there are different types of ssl libraries used by different versions of indy, so make sure you carefully read that page or you'll get errors.
you will find a couple of links to some external demos which will help you see how to use ssl in your peojct and also, you cna take a peak to my more adnvaced demos which also use SSL http://www.ciuly.com/delphi/indy/

because some users have a hard time getting their first ssl project working, I suggest you copy the ssl dll's in the same folder as your project exe.
if you really cannot get it to work, then tell me the exact version of your indy and the exact version and datetime 9and size, to be on the safe side) of both ssl dlls.
Avatar of maxoss
maxoss

ASKER

Hello and thanks for helping me.

>>You need to setup a ssl io handler for that.
Is that component IdSSLIOHandlerSocket?

On the indyproject.org website, almost every link is dead or redirects to www.intelicom.si which has no information about it.

I downloaded openssl-0.9.8i-i386-win32.zip and unzipped the DLLs in my project folder.

How can I know my Indy version for sure? I see dclindy70 in my packages. I tried to download a newer version but all links are dead.

Else, would there be an other alternative than indy to get an image from a HTTPS?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maxoss

ASKER

I got it to work! Here is what I did:

OnFormCreate: IdSSLOpenSSLHeaders.Load;
and I mixed the following code with my previously written code and it works perfectly!

Thank you for your advice though!
//Found on http://delphi.ktop.com.tw/board.php?cid=30&fid=67&tid=89601
 
   1. procedure TForm1.FormCreate(Sender: TObject);  
   2. var  
   3. FileName: String;  
   4. SSLIOHandler: TIdSSLIOHandlerSocketBase;  
   5. begin  
   6. FileName:='tops.gif';  
   7. SSLIOHandler:= TIdSSLIOHandlerSocketBase.Create;  
   8. try  
   9.     IdHTTP1.IOHandler:= SSLIOHandler;  
  10.     Dir:=ExtractFileDir(Application.Exename) + FileName;  
  11.     fs := TFileStream.Create(Dir, fmCreate);  
  12.     IdHTTP1.Get('https://nas.immigration.gov.tw/nasf/images/tops.gif' , fs);  
  13. finally  
  14.     fs.Free;  
  15.     SSLIOHandler.Free;  
  16. end;  
  17. end;  

Open in new window