TfphttpClient, download with progressbar using Post method lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- cpalx · 2021-08-18 13:28 Hello, i found this https://forum.lazarus.freepascal.org/index.php?topic=21824.0 and works perfectly, but with Get method, i need use Post method sendind variables. any help please. ---------------------------------------------------------------------- balazsszekely · 2021-08-19 12:42 Hi cpalx, QuoteI need use Post method sendind variables. any help please. 1. PHP Save the following script as "lazarus.php", then upload to your local/remote server. Make sure the server is running. The script is self explanatory, it will add/multiply two numbers received by POST then echo back the result: Code: PHP  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 2. Lazarus Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses fphttpclient; procedure TForm1.Button1Click(Sender: TObject);var  FPHTTPClient: TFPHTTPClient;  SL: TStringList;  Str: String;begin  FPHTTPClient := TFPHTTPClient.Create(nil);  try    FPHTTPClient.AllowRedirect := True;    SL := TStringList.Create;    try      SL.Add('a=' + IntToStr(9));      SL.Add('b=' + IntToStr(6));      try        Str := FPHTTPClient.SimpleFormPost('http://localhost/lazarus.php', SL);      ShowMessage(Str);      except        on E: exception do          ShowMessage(E.Message);      end;    finally      SL.Free;    end;  finally    FPHTTPClient.Free;  end;end; ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-08-19 13:13 Hey GetMem, Please don't chew my head off for what I'm about to say, cuz I don't intend any harm. The OP wants a progress download that is originated by a POST, not a GET. Your code only addresses the part where you do the POST, but then it has no code to deal with a FILE DOWNLOAD that is triggered from said POST. While it is a good way of showing him how to modify the original code in order to swap a GET to a POST, you fail to mention that and it's confusing, well, at least in my point of view. I hope I didn't offend in any way, cuz, and I can't stress this enough, that was not my intention!! Cheers, Gus ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-08-19 13:30 Hey cpalx, First of all you have to notice one thing: TFpHTTPClient has a slight issue that demands you do a HEAD on the file to get the correct size of the target file you want to download. If you don't perform the HEAD on the file then the first call to the Progress Event will have the file size set to 0. Now, as you can ascertain, this is gonna be an issue if we change from GET to POST, since you will not be able to perform the HEAD on the target file. At the moment I'm unaware of why TFpHTTPClient does that first call with file size equal to 0, but maybe you have the time to dive into the code and find out if it's something that needs to be reported. If you don't want to rely on a TStream descendant to have your progress you can use the code I'm attaching that has a multi-file download in both Threaded and Non-Threaded way with a Modal Form. The only thing you have to change is the method you want to use and that is achieved by the code GetMem provided. Oh, and eliminate the call to HEAD. A little bit of fiddle will make that work and you can have the first call have size 0 with no issue at all since we're not descending from a TStream that needs to have the size on the first call of that OnNotify. Please feel free to use my code and ask me anything about it if you find yourself stuck. Cheers, Gus ---------------------------------------------------------------------- balazsszekely · 2021-08-19 13:45 @Gus QuoteThe OP wants a progress download that is originated by a POST, not a GET. Your code only addresses the part where you do the POST, but then it has no code to deal with a FILE DOWNLOAD that is triggered from said POST. Fair enough, I should have read the thread title more carefully. I posted in the past both download and upload with progress(fphttpclient). Using POST instead of GET is just a minor detail in my opinion. ---------------------------------------------------------------------- valdir.marcos · 2021-08-19 14:09 Quote from: GetMem on August 19, 2021, 03:45:31 pmI posted in the past both download and upload with progress(fphttpclient). Using POST instead of GET is just a minor detail in my opinion.@GetMem Please, could you share the link of the referred example? Thanks. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-08-19 14:17 Hey Getmem, Quote from: GetMem on August 19, 2021, 03:45:31 pmFair enough, I should have read the thread title more carefully. Hey, you're a very good guy and I'll let it slide Quote from: GetMem on August 19, 2021, 03:45:31 pmI posted in the past both download and upload with progress(fphttpclient). Using POST instead of GET is just a minor detail in my opinion. To be quite honest I couldn't agree more!! I really didn't want to offend the OP's intelligence and just blurt out: Well, just don't use the GET and use a POST then!! That would've been rude and not helpful at all And on that premise, of being helpful that is, I thought I would make it clear that your solution was just half a solution. I hope I wasn't too harsh nor too pedantic, cuz I hate it when someone does it to me and I really don't want to make that awful mistake!! Cheers, Gus ---------------------------------------------------------------------- balazsszekely · 2021-08-19 14:26 @valdir.marcos QuotePlease, could you share the link of the referred example?Download: https://forum.lazarus.freepascal.org/index.php/topic ,52773.msg389901.html#msg389901 Upload: https://forum.lazarus.freepascal.org/index.php/topic,44795.msg 315238.html#msg315238 QuoteThanks.You're welcome! ---------------------------------------------------------------------- cpalx · 2021-08-19 15:43 i will study your codes, thanks.