I'm having trouble connecting to my DropBox account via TIdHTTP
and I don't know what to do anymore. I want to send a simple text file to DropBox in the first stage.
procedure TForm2.btn1Click(Sender: TObject);
const
API_URL = 'https://content.dropboxapi.com/2/files/upload';
cFile = 'D:\testfile.txt';
var
wAccessToken : string;
Source: TFileStream;
IdHTTP: TIdHTTP;
Res : string;
Ssl: TIdSSLIOHandlerSocketOpenSSL;
begin
wAccessToken := 'muj_token';
IdHTTP := TIdHTTP.Create(nil);
try
(*
ShowMessage('Indy version: ' + IdHTTP.Version);
RESULT MESSAGE : INDY 10.5.9.0
*)
IdHTTP.HandleRedirects := True;
ssl := TIdSSLIOHandlerSocketOpenSSL.Create();
ssl.SSLOptions.Method := sslvTLSv1_2;
ssl.SSLOptions.Mode := sslmUnassigned;
ssl.SSLOptions.VerifyMode := [];
ssl.SSLOptions.VerifyDepth := 0;
ssl.host := '';
Source := TFileStream.Create(cFile, fmOpenRead);
IdHTTP.IOHandler := ssl;
IdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + wAccessToken;
IdHTTP.Request.CustomHeaders.Values['Dropbox-API-Arg'] :=
'{ "autorename": false,"mode": "add","mute": false,"path": "/test.txt","strict_conflict": false}';
IdHTTP.Request.CustomHeaders.Values['Content-Type'] := 'application/octet-stream';
Memo1.Lines.Add(IdHTTP.Request.CustomHeaders.Text);
Res := IdHTTP.Post(API_URL, Source);
finally
IdHTTP.Free;
end;
But, after the POST
command, I get the error:
Project Project2.exe raised exception class EIdOSSLUnderlyingCryptoError with message "Error connecting with SSL. error:1409442E:SSL routines:SSL3_READ_BYTES:tlsv1 alert protocol version"
I don't know how to proceed, there is a stupid mistake somewhere. I found similar problems on StackOverflow:
Post problems with Indy TIdHTTP
And many other forums. Somewhere it says it may be an old Indy (which it is), but DropBox probably has TLS v1.2 required though TIdHTTP
enables it:
ssl.SSLOptions.Method := sslvTLSv1_2
For the Request track, I stuck to DropBox's API structure:
DROPBOX API DOCUMENTATION
https://www.dropbox.com/developers/documentation/http/documentation#files-upload
Get access token for:
****************************************************** **************
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer <get access token>" \
--header "Dropbox-API-Arg: {\"autorename\":false,\"mode\":\"add\",\"mute\":false,\"path\":\"/Homework/ math/Matrices.txt\",\"strict_conflict\":false}" \
--header "Content-Type: application/octet-stream" \
--data-binary @local_file.txt
****************************************************** **************
Even more information:
- Delphi XE3
- Indy 10.5.9.0
- with the exe I have the OpenSSL files
libeay32.dll
(1.0.2.17) andssleay32.dll
(1.0.2.17) - but that will not be it. If I throw them away the error is the same. - DropBox requires TLS 1.2 since April
On some forums, they wrote the same error with old OpenSSL files, old Indy, sending via TLS, which is not supported by the addressee. But I don't feel either way.
I downloaded OpenSSL from https://github.com/IndySockets/OpenSSL-Binaries
openssl-1.0.2u-x64_86-win64.zip
(I don't know if it's good, there are a bunch of them in the table with differences in the name "r", "s", "t", "u", I chose the last one).