Jump to content

polasss

Members
  • Content Count

    13
  • Joined

  • Last visited

Posts posted by polasss


  1. On 4/1/2021 at 6:15 PM, Remy Lebeau said:

    The TIdHTTP version would look like this:

    
    uses
      ..., IdHTTP, IdSSLOpenSSL, IdMultipartFormDataStream;
    
    var
      HTTP: TIdHTTP;
    .....

     

     

    Hi, I'm trying to convert the cUrl for TIdHttp but no success. Can you please tell me where i am wrong? (BAD REQUEST)

    curl https://api.dropbox.com/oauth2/token \  -d code=<AUTHORIZATION_CODE> \  -d grant_type=authorization_code \  -u <APP_KEY>:<APP_SECRET>

    My (bad) convert:   ( ........ SOLVED !!!  - see the solution below ............)

       IdHTTP := TIdHTTP.Create(nil);
       try
          //'curl https://api.dropbox.com/oauth2/token \     -d code=<AUTHORIZATION_CODE> \     -d grant_type=authorization_code \     -u <APP_KEY>:<APP_SECRET>'
          ssl := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
          ssl.SSLOptions.SSLVersions  := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
          ssl.SSLOptions.Mode         := TidSSLMode.sslmUnassigned;
          ssl.SSLOptions.VerifyMode   := [];
          ssl.SSLOptions.VerifyDepth  := 0;
          ssl.host                    := '';
          //ssl.OnStatusInfoEx          := __IdSSLIOHandlerSocketOpenSSL1StatusInfoEx; 
          ssl.DefStringEncoding       := IndyTextEncoding_UTF8;
          IdHTTP.HandleRedirects  := True;
          IdHTTP.IOHandler        := ssl;
          IdHTTP.Request.BasicAuthentication := False;
          IdHTTP.Request.Username := 'MY_APP_KEY';
          IdHTTP.Request.Password := 'MY_APP_SECRET';
    
          Params := TIdMultipartFormDataStream.Create;
          try
             Result := True;
             Params.AddFormField('code', 'MY_AUTH_CODE');
             Params.AddFormField('grant_type', 'authorization_code');
             aStatus := IdHTTP.Post('https://api.dropbox.com/oauth2/token', Params);
          except
             on E: EIdHTTPProtocolException do
             begin
                Result := false;
                aStatus := ErrorResult(IdHTTP.ResponseText);
             end;
          end;
          (**)
       finally
          //SSLstatusInfo := fStatusSSLInfo;
          ssl.Free;
          IdHTTP.Free;
       end;

    *************   SOLVED  *******************************************************

          IdHTTP.Request.BasicAuthentication := TRUE;
          IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';

    ********************************************************************************

     

    and USES is displayed incorrectly

    uses
      ..., IdMultipartFormDataStream;

    correct

    uses
      ..., IdMultipartFormData;

    thanks for Lemy !

     

     


  2. Delphi Xe-3 - once the standard installation of VCL has turned into a pain - after running install.bat, an installation window opens without a standard tree for choosing to install components and other components (see pict 1) - there is nothing to install. After pressing the install button, the installation is completed immediately, but of course nothing is installed.

    Standard window see pict 2 (of course without error message)

    It must have something to do with the fact that I reinstalled all of XE3 from the D drive back to the C drive (this was again prompted by the Indy installation...). I spent an hour manually cleaning the registry of JCL and JVCL entries. Nothing.

    The same problem was solved here
    https://stackoverflow.com/questions/28348918/delphi-xe-installation-of-jedi-jcl-2-6-on-win8-x64
    but for me there is no solution

    error-win.png

    standard-win.png


  3. I save a JSON file on Dropbox, after reading it I don't get it in the correct UTF-8 state as it left, please advise.
    I am sending Czech characters

    {"auth":{"text1":"cz_čřšť","text2":"ýáíé","int":10}}

    I will get 

    {"auth":{"text1":"cz_èø","text2":"ýáíé","int":10}}

    POST code

    procedure TForm2.btn_Upload_JsonClick(Sender: TObject);
    const
      API_URL = 'https://content.dropboxapi.com/2/files/upload';
    var
      IdHTTP: TIdHTTP;
      Res : string;
      Ssl: TIdSSLIOHandlerSocketOpenSSL;
      Json : string;
      Req_Json:TStringStream;
    begin
      Json := '{"auth":{"text1":"cz_čřšť","text2":"ýáíé","int":10}}';
      Req_Json:=TstringStream.Create(Json);
      Req_Json.Position:=0;
    
      IdHTTP := TIdHTTP.Create(nil);
      try
        Memo1.Lines.Clear;
        IdHTTP.HandleRedirects := True;
        ssl := TIdSSLIOHandlerSocketOpenSSL.Create();
        ssl.SSLOptions.Method := sslvTLSv1_2;
        ssl.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
        ssl.SSLOptions.Mode := TidSSLMode.sslmUnassigned;
        ssl.SSLOptions.VerifyMode := [];
        ssl.SSLOptions.VerifyDepth := 0;
        ssl.host := '';
    
        IdHTTP.IOHandler := ssl;
        IdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + myAccessToken;
        IdHTTP.Request.CustomHeaders.Values['Dropbox-API-Arg'] :=
               '{ "autorename": false, "mode": "add", "mute": false, "path": "/CUZK/test3.json", "strict_conflict": false }';
        IdHTTP.Request.CustomHeaders.Values['Content-Type']  := 'application/octet-stream';
        IdHTTP.Request.CharSet:='utf-8';
    
        Memo1.Lines.Add('** IdHTTP.Request.CustomHeaders.Text **');
        Memo1.Lines.Add(IdHTTP.Request.CustomHeaders.Text);
        Memo1.Lines.Add('** ssl.OnStatusInfoEx **');
        ssl.OnStatusInfoEx := IdSSLIOHandlerSocketOpenSSL1StatusInfoEx;
    
        (**)
    
          Res := IdHTTP.Post(API_URL, Req_Json);
          memo1.Lines.Add('------------------------------------');
          Memo1.Lines.Add(Res);
    
      finally
          IdHTTP.Free;
          Req_Json.Free;
      end;

    GET CODE

    procedure TForm2.btn_Download_File_Click(Sender: TObject);
    const
      API_URL = 'https://content.dropboxapi.com/2/files/download';
    var
      Source: TMemoryStream;
      IdHTTP: TIdHTTP;
      Res : string;
      Ssl: TIdSSLIOHandlerSocketOpenSSL;
    begin
    
      IdHTTP := TIdHTTP.Create(nil);
      try
        IdHTTP.HandleRedirects := True;
        ssl := TIdSSLIOHandlerSocketOpenSSL.Create();
        ssl.SSLOptions.Method := sslvTLSv1_2;
        Ssl.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
        ssl.SSLOptions.Mode := TidSSLMode.sslmUnassigned;
        ssl.SSLOptions.VerifyMode := [];
        ssl.SSLOptions.VerifyDepth := 0;
        ssl.host := '';
    
        Source := TMemoryStream.Create;
    
        IdHTTP.IOHandler := ssl;
        IdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + myAccessToken;
        IdHTTP.Request.CustomHeaders.Values['Dropbox-API-Arg'] := '{ "path": "/CUZK/test3.json" }';
        IdHTTP.Request.CharSet := 'utf-8';
    
          Res := ansitoutf8(IdHTTP.Get(API_URL));
          memo1.Lines.Add('------------------------------------');
          Memo1.Lines.Add(Res);
    
      finally
          IdHTTP.Free;
          Source.Free;
      end;
    
    end;

     


  4. So done! 👍 Error 401 unauthorized resolved - Access Token expired, after renewing it I got a JSON response back. I'm still figuring out why, but that's another song.

    Thanks a lot indeed, especially Remy Lebeau!

     

    • update to latest Open SSL bin files https://indy.fulgan.com/SSL/?C=M;O=D
    • if the software is v32, it is necessary to use openssl-1.0.2u-i386-win32.zip (even if the system is w64)
    • reinstall Indy to the latest version (even though reinstalling Indy is a horror, reinstalled a total of 6 times, each time a different error, I ended up with Indy without components - installation just doesn't work)
    • Current version of Indy https://github.com/IndySockets/Indy
    • How to reinstall Indy https://github.com/IndySockets/Indy/wiki/Updating-Indy
    • I had Indy on a different drive than "C" and that was probably a mistake, here too but different error messages every time
    • I put the Open SSL bin files directly to the exe, to be sure I set the file path 
      IdOpenSSLSetLibPath(ExtractFilePath(Application.ExeName))

  5. First output:
    - reinstall BDE xe3 (I put it back from drive "D" where "C" should be)
    - I added the current Open SSL dll to the exe
    - I added to the code what Remy wrote

     

    extract from memo1:

    before/connect initialization
    before/connect initialization
    SSLv3 write client hello A
    protocol version
    SSLv3 read server hello A

     

    the error remained, I will try to upgrade Indy after 100 attempts (I googled again, one information was that Indy wants "C" drive by default)

    Note: I have done the upgrade many times, each time it behaves a little differently (other missing dcu, etc.). I wonder.


  6. OK, thank you very much indeed, I appreciate the time of everyone who contributed.
    So I have a lot of work ahead of me today.
    1:  reinstall BD XE3 - I reached into the gray paths (Library, Browsing path), I deleted the old INDY and it was not possible to install the new one... let's go clean ;-(
    2:  I downloaded the latest OpenSSL binary, the version numbers match
    3:  I install (at least I hope) the new INDY (fourth, now I know that it is possible to bypass "paclientcore". We'll see what happens when installing dclIndyCore and Protocols, here it reported the error hard)
    4:  I will add StatusInfo (see above) and try the DropBox test
    - and then it will be midnight and if it doesn't work ...

     

    Another stupid question please:
    Isn't it reasonable to make a restore point in OS WIN 10 after step 2? Will the restore really return the system to its original state without any ballast?

     

    I suppose I'll be in touch again, thanks again.


  7. 4 hours ago, WillH said:

    I've just tried your code with Indy version: 10.6.2.0. The SSL part works. I made a change for logging but that's it.

    Check that the dlls you have match the bitness of your compiled application. A 64bit application needs 64bit openSSL dlls.

    Otherwise use the latest Indy version or alternate HTTP code such as the ones included in mORMot based on the WinHTTP drivers. At some point tls1.3 will become the minimum and as far as I know Indy does not support it yet.

     

    ;-( So I won't do that now, I removed the old Indy and started the upgrade to the latest version exactly as instructed
    https://github.com/IndySockets/Indy/wiki/Updating-Indy
    and I'm back in ...

    compilation error

    [dcc32 Fatal Error] IndySystem170.dpk(34): E2202 Required package 'paclientcore' not found

    What the hell am I missing? Google finds paclientcore on 4 sites but nothing. I deleted some gray paths in "Library path" and Browsing path", would that be it?
    Please, give me an advice! 


  8. I've been struggling for 3 days to get OpenSSl working, I was advised to upgrade to a new version of Indy (XE3, Indy 10.5.0).
    Ok, I followed the instructions exactly
    https://github.com/IndySockets/Indy/wiki/Updating-Indy
    and I'm back in ...

    compilation error

    [dcc32 Fatal Error] IndySystem170.dpk(34): E2202 Required package 'paclientcore' not found

    What the hell am I missing? Google finds paclientcore on 4 sites but nothing.
    Please, give me an advice! 


  9. and does the above procedure work?
    I'm struggling with something similar - access to Dropbox and still errors

     

    https://en.delphipraxis.net/topic/7838-delphi-xe-error-connect-dropbox-via-indy-tidhttp-htttps/?tab=comments#comment-65621

     


  10. 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 "error: 1409442E:SSL routines: SSL3_READ_BYTES:tlsv 1 alert protocol" - class EIdOSSLUnderlyingCryptoError with message "Error connectin with SSL"

    http://imgway.cz/m/hneT.jpg

    I don't know how to proceed, there is a stupid mistake somewhere. I found similar problems on

    https://stackoverflow.com/questions/1742900/tidhttp-in-indy-10 , https://stackoverflow.com/questions/7762584/post-problems-with-indy-tidhttp

     and many other forums. Somewhere it says it may be old INDY (which it is), but DROPBOX's probably has the TLS v1.2 required when TIDHTTP enables it ssl.SSLOptions.Method := sslvTLSv1_2

    For the Request track, I stuck to the DROBOX.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 Open SSL files libeay32.dll (v. 1.0.2.17) and  ssleay32.dll (v. 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 from April

    On some forums they wrote the same error with old Open SSL files, old INDY, sending via TLS which is not supported by the addressee. But I don't feel either way. I downloaded Open SSL from https://github.com/IndySockets/OpenSSL-Binaries file 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", he chose I'm the last one).

    Thanks for any advice.


  11. how to use ExecuteScript to get the complete page source - something like browser does with

    view-source: https//..any..web..page

    If I call

    ExecuteScript wbBrowser.ExecuteScript('document.documentElement.outerHTML') 

    i only get what is displayed on the page. However, there are web pages that display data in a table and currently only display a portion of the records (e.g. 1-10 out of 1000). By calling 

    wbBrowser.ExecuteScript('document.documentElement.outerHTML') i only get the current 1-10, but the browser will display the complete data using 

    view-source: https//****).

    Unfortunately, for data protection reasons I can't show the source of the page.

×