[SOLVED] how to "save as" result from PHP script ? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- mirce.vladimirov · 2017-06-20 13:08 My application should open a HTTP link like "http://somepage.com/012301230123.php" , and this PHP script  prepares and returns a CSV file and I should retrieve the data stored within it, and finaly write the data to a database  table. It's easey under Linux console, there is curl : Code: [Select]curl http://somepage.com/012301230123.php  > mycsvfile.csv But my application should run under windows. Is there similar tool to be used under Lazarus ? Note:I am already using Indy for ftp download/upload files, but I've never retrieved data like in this example. ---------------------------------------------------------------------- turrican · 2017-06-20 13:29 You can implement Indy HTTPClient : 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 var  IdHTTP1: TIdHTTP;  CSV: TMemoryStream;begin  CSV := TMemoryStream.Create;  IdHTTP1 := TidHTTP.Create;  try    try      IdHTTP1.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1';      IdHTTP1.Get('http://http://somepage.com/012301230123.php', CSV);    except      on E: Exception do      begin        {$IFDEF DEBUG}ShowMessage('get error:'+E.Message){$ENDIF};      end;    end;  ShowMessage(IntToStr(CSV.Size));  finally    CSV.Free;    IdHTTP1.Free;  end;end; ---------------------------------------------------------------------- mirce.vladimirov · 2017-06-20 13:38 Thank you very much. There are links that apeared AFTER I posted my question, sorry, I've searched previosly but none came up. Here are the links : http://wiki.freepascal.org/fphttpclient#Get_body_of_a_web_page_via_HTT P_protocol http://forum.lazarus.freepascal.org/index.php/topic,29192.msg183851/to picseen.html I will test Indy and this fphttpclient and post here what was best. Thank you one more time. ---------------------------------------------------------------------- turrican · 2017-06-21 15:10 Hi! No problem, you are welcome. When client gets a response from the server take and eye to response's content type (application/json for example) for save as binary, text, etc... ---------------------------------------------------------------------- mirce.vladimirov · 2017-06-22 10:57 Since I expect only *.csv data I decided to use fphttpclient. I believe that's the simplest solution, here's my code : 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  myhttp : TFPCustomHTTPClient; lista: TStringList; begin   myhttp := tfpcustomhttpclient.Create(Nil);  lista:=TStringList.Create;  lista.Clear;  lista.Add(myhttp.get('http://somewebsite.com/012301230123.php')) ;  lista.SaveToFile('c:/path_to_myfile/myfile.csv');  lista.Free;  myhttp.Free;  ShowMessage('Done !'); // now do everything else I need to do with the *.csv fileend;   I will say one more time, I expect only text data in  *.csv files and  that I recieve that is the main reason why i decided for this. It's a different thing if response could contain binary data, no doubt that Indy is better for that. ---------------------------------------------------------------------- rvk · 2017-06-22 11:12 Quote from: mirce.vladimirov on June 22, 2017, 12:57:49 pmI will say one more time, I expect only text data in  *.csv files and  that I recieve that is the main reason why i decided for this. It's a different thing if response could contain binary data, no doubt that Indy is better for that.There are class functions in TFPHTTPClient which you can use without creating a instance yourself. Like TFPHTTPClient.SimpleGet(). You can call that directly And if you use the version with TStream as result you can read binary files too. So the simplest version would be: 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  FileStream: TFileStream;begin  FileStream := TFileStream.Create('c:/path_to_myfile/myfile.csv', fmCreate);  try    TFPHTTPClient.SimpleGet('http://somewebsite.com/012301230123.php', FileStream);    ShowMessage('Done !');  finally    FileStream.Free;  end;   // now do everything else I need to do with the *.csv file end;