Curl post lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- michoux · 2019-07-15 13:26 Hello all. I am searching for lazarus solution to post a file content to php web. With curl I do following: curl -X POST --data-binary @path/to/my-file.txt http://example.com/ Is there a lazarus option for this? Thanks ---------------------------------------------------------------------- engkin · 2019-07-15 15:53 Try: 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..  TFPHTTPClient.SimplePost('http://example.com/', 'path/to/my-file.txt'); Some servers need a User-Agent, others might redirect you from, say, http to https. For more control try: 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..  with TFPHTTPClient.Create(nil) do  try    AllowRedirect := True;    AddHeader('User-Agent','curl/7.37.0');    Post('http://example.com/', 'path/to/my-file.txt');  finally    Free;  end; ---------------------------------------------------------------------- michoux · 2019-08-12 13:22 As I know the post or simple post will post a file which is already on the server. I am posting a local file from my PC ---------------------------------------------------------------------- michoux · 2019-08-12 17:50 curl command works great but I want to get rid of windows black window that alway show when running curl.exe ---------------------------------------------------------------------- bytebites · 2019-08-12 18:07 Quote from: michoux on August 12, 2019, 03:22:31 pmAs I know the post or simple post will post a file which is already on the server. Not true aka false. ---------------------------------------------------------------------- michoux · 2019-08-14 06:29 Here is how my scripts on server works. I can call it this way with file http://mysite.com/send.php?xml=file.xml Or I simply call curl with syntax from above curl -X POST --data-binary @path/to/my-file.txt http://mysite.com/send.php I have tried simplepost but it only accepts files from server, so I need  to first upload file from local PC to server in same location as my php scripts resides and then call http://mysite.com/send.php?xml=./file.xml Here is my php which I call ***************************** 0) {    $xml = new MyXML();    echo $xml->ReadXML($xmlData); } else {    echo MyXML::WriteErrorXML('XML Data Empty'); } ?> ********************************* ---------------------------------------------------------------------- Leledumbo · 2019-08-14 09:18 Quote from: michoux on August 14, 2019, 08:29:21 amHere is how my scripts on server works. I can call it this way with file http://mysite.com/send.php?xml=file.xml Or I simply call curl with syntax from above curl -X POST --data-binary @path/to/my-file.txt http://mysite.com/send.php Those two are not the same, the former issues a GET request with parameter named xml containing a string file.xml, the second one issues a POST request with the content of path/to/my-file.txt as raw request body. TFPHTTPClient.SimplePost does the same as the latter. Quote from: michoux on August 14, 2019, 08:29:21 amHere is my php which I call ***************************** This php will just read the input and echo it back for the program to display. Edit: Had this first implemented as helper procedure but that might complicate it too much. ---------------------------------------------------------------------- michoux · 2019-08-14 14:21 rvk - Thanks a lot, this. woooooorks Just need to correct TFileStream.Create; to TFileStream.Create(''); Sorry for my not-knowledge - I use to program in Pascal/Delphi 20 years ago Thanks again to all for this help .. Regards Michoux ---------------------------------------------------------------------- rvk · 2019-08-14 14:46 Quote from: michoux on August 14, 2019, 04:21:29 pmJust need to correct TFileStream.Create; to TFileStream.Create(''); You mean TStringStream.Create('') ?? The definition of TStringStream.Create is this: 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   TStringStream = class(TBytesStream)  public    constructor Create(const AString: string = ''); overload;The = '' after AString: string means that the AString is optional. And if left out the '' will be used. So .Create(''); isn't strictly necessary. .Create; works fine too. It seems there isn't much need for posting a file raw in the body (otherwise there would have been a function for it). Normally the SimpleFileFormPost() is used and then a "fieldname" is provided (could be anything). In PHP you could then access $_FILES to retrieve the files and content (in that case the content is already written to a temp-file). But posting it as raw body and using php://input is also possible. The only downside is that you can't provide a filename (which is possible with the form-date and $_FILES). No problems about your knowledge. We're glad to help. ---------------------------------------------------------------------- michoux · 2019-08-14 19:49 Hi, Sorry Response := TStringStream.Create; to Response := TStringStream.Create(''); Response := TStringStream.Create; did not work for me, got an error ... I did not develop the php sources and I am not really allowed to change them, just use them as they are )) This is app to load live data from sport events in real time. I am coding connector between timing software and this web app to transfer data in xml format ... DB is sqlite and I have some problems with DB lock, but I will ask this in other forum ... Thanks again for help Regards Michoux ---------------------------------------------------------------------- rvk · 2019-08-14 20:02 Quote from: michoux on August 14, 2019, 09:49:58 pmResponse := TStringStream.Create; did not work for me, got an error ... Ah, ok. Maybe you have an older Lazarus/FPC installation. I'm not sure at what point the AString became optional (because for me it is, in the trunk-version).