[WORKAROUND] TFPHTTPClient.Put(...) not working lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- eny · 2015-09-03 13:23 When using the methods FORMPOST(...), DELETE(...) or GET(...) from TFPHTTPClient there is no problem. However when using PUT the program blocks. Has anyone ever used this and got it working? It can be easily tested with the 2 examples in the fcl-web folder. - compile and run httpserver\simplehttpserver.exe - in program httpclient\httppost, change line "FormPost(ParamStr(1),vars,f);" to "put(Paramstr(1), vars);" - run the the program - it blocks (the original line with FormPost() does work). ---------------------------------------------------------------------- derek.john.evans · 2015-09-03 14:17 I just tested it, and accidentally caused a "block", and lost a file while doing so. With FormPost(), the filename is opened for reading: ie: Code: [Select]TFileStream.Create(AFileName,fmOpenRead or fmShareDenyWrite);  With Put, LocalFileName is actually the response, not a file to be sent. ie: Code: [Select]F:=TFileStream.Create(LocalFileName,fmCreate);    Which is kinda odd to me. Indy has: Code: [Select]procedure Put(AURL: string; ASource, AResponseContent: TStream); overload;  Which is what I thought a PUT was. Anyway, it looks like fphttpclient doesn't have a working PUT. As for your block. I selected a file that was locked by Lazarus, and I got a block, until I closed Lazarus, and bingo, my file was cleared. I think you need to use Indy or Synapse if you want a PUT. ---------------------------------------------------------------------- Leledumbo · 2015-09-03 17:15 Quote from: derek.john.evans on September 03, 2015, 04:17:28 pmI think you need to use Indy or Synapse if you want a PUT. Reporting it to the bugtracker is a wise thing to do, too. ---------------------------------------------------------------------- derek.john.evans · 2015-09-03 17:31 Quote from: Leledumbo on September 03, 2015, 07:15:41 pmReporting it to the bugtracker is a wise thing to do, too. yaa. I'm getting there  Only just got a SVN version of FP/Lazarus setup yesterday, so now I can confirm if a issue is still there. ---------------------------------------------------------------------- eny · 2015-09-04 12:20 I dug a bit deeper and found a maze of overloaded methods, duplicated code and functional errors in method definitions: the problem is that PUT does not allow request body data while it should (like the POST does). Because of this the property RequestBody does not have a value and that blocks the http traffic. Probably making the server wait for data. The workaround: assign a valid stream handle to RequestBody before the call. Something like:Code: [Select]var hc: TFPHttpClient;     ss: TStringStream; begin   hc := TFPHttpClient.Create(nil);   ss := TStringStream.Create('');  // Bug in TStringStream: it does not have a parameterless constructor   ....   ss.Position := 0;        // be sure to be sure   hc.RequestBody := ss;   hc.Put('http://my.put.url');   ..   ss.Free;   hc.Free; end; ---------------------------------------------------------------------- derek.john.evans · 2015-09-04 12:26 Cool  Good to know. God, I must be blind! The comment for Put is: // Put URL, and Requestbody. Return response in Stream, File, TstringList or String;  I guess I didn't know there was a field called Requestbody. O, the shame!