Recent

Author Topic: [WORKAROUND] TFPHTTPClient.Put(...) not working  (Read 4953 times)

eny

  • Hero Member
  • *****
  • Posts: 1634
[WORKAROUND] TFPHTTPClient.Put(...) not working
« on: September 03, 2015, 03:23:13 pm »
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).
« Last Edit: September 04, 2015, 02:20:37 pm by eny »
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

derek.john.evans

  • Guest
Re: TFPHTTPClient.Put(...) not working
« Reply #1 on: September 03, 2015, 04:17:28 pm »
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

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TFPHTTPClient.Put(...) not working
« Reply #2 on: September 03, 2015, 07:15:41 pm »
I 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

  • Guest
Re: TFPHTTPClient.Put(...) not working
« Reply #3 on: September 03, 2015, 07:31:32 pm »
Reporting it to the bugtracker is a wise thing to do, too.

yaa. I'm getting there  ;D Only just got a SVN version of FP/Lazarus setup yesterday, so now I can confirm if a issue is still there.


eny

  • Hero Member
  • *****
  • Posts: 1634
Re: TFPHTTPClient.Put(...) not working
« Reply #4 on: September 04, 2015, 02:20:00 pm »
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;
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

derek.john.evans

  • Guest
Re: [WORKAROUND] TFPHTTPClient.Put(...) not working
« Reply #5 on: September 04, 2015, 02:26:33 pm »
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!

 

TinyPortal © 2005-2018