1 (edited by SandBird 2025-02-21 02:13:43)

Topic: Is it possible to download an image using WinHTTPReq?

Hello,

I was trying to download a file from a website mobygames using HTTPGet or HTTPGetFiles however it gives me an error (see error below) which I suspect maybe it's because the DLL's (libssl32 and libeay32) are too old (version 1.0.2)? - oddly it doesn't happen with other sites I tested.

So I opted to using WinHTTPReq that I found people suggest while searching the forum and it works without any issues for HTML pages but I am unsure how to download an image or any kind of a binary file (I tried adding an example link but the forum won't let me).

Can anyone please advise as to how to achieve it? (if it's even possible).

Any input would be highly appreciated and thank you in advance!

Update: I see that the attachment wasn't added so what the error says is:
Error connecting with SSL.
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

2 (edited by sparrow 2025-02-21 07:19:34)

Re: Is it possible to download an image using WinHTTPReq?

OpenSSL https://github.com/IndySockets/OpenSSL- … ree/master

If you look at the search engine responses to your error, you can see that the main source of problems is related to proxy usage and settings or incorrect port settings.

Re: Is it possible to download an image using WinHTTPReq?

If very briefly then...

var
  WinHttpReq : Variant;
  Stream  : Variant;
  url : String ;
begin
  WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');

  url := 'your link to the file' ;
  WinHttpReq.open('GET',url,false);
  WinHttpReq.Send;

if ...There should be a check for the connection response here. ... then
begin
  Stream  :=  CreateOleObject('ADODB.Stream');
  Stream.Open;
  Stream.Type := 1;
  Stream.Write(WinHttpReq.responseBody);
  Stream.SaveToFile( 'File name to save');
  Stream.Close;
end else ... There is an error message here. ...;
  WinHttpReq := nil;
end;

Description and options of COM objects on the developer's website. Examples on the Internet.

Re: Is it possible to download an image using WinHTTPReq?

sparrow, thank you so much for the prompt help!

As for the HTTPGet etc. error, I think I found the same post that you did which indicates that it's a port/proxy issue however I don't use a proxy nor do I use VPN etc. and so far the issue is only for the specific site I mentioned, not others.

I went with the WinHttp option since it's seems what was recommended as an alternative and it worked without any issues - i couldn't find any downside for using it and perhaps it is even more "future proof".

Thank you again, I managed to use the method you mentioned to download binary files without any issues!