Recent

Author Topic: fcl-web/fphttpclient multiple queries  (Read 5580 times)

valerife

  • New Member
  • *
  • Posts: 10
fcl-web/fphttpclient multiple queries
« on: February 20, 2017, 10:09:45 am »
Hello,

I am currently using fphttpclient in order to makes queries to an API with POST request.
My issue is the following one : I can only make on request by object http created.

Is it the normal behaviour of fphttpclient ?

More details about my usage of fphttpclient :

This is how i create my object
Code: Pascal  [Select][+][-]
  1. FPHttpClient := TFPHttpClient.Create(nil);


I set up some headers at the initialization with the following method
 
Code: Pascal  [Select][+][-]
  1. FPHttpClient.AddHeader('Auth-key', x);

I will finally send a bunch of requests in a loop using the following method (catching and handling errors).
Code: Pascal  [Select][+][-]
  1. FFPHttpClient.RequestBody := BodyStream; //BodyStream is a created stringStream containing my POST datas
  2. try
  3.   FPHttpClient.HTTPMethod('POST', URL, AnswerStream, [201]);
  4. finally
  5.   FreeAndNil(BodyStream);
  6. end;
  7.  

 
Thanks

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: fcl-web/fphttpclient multiple queries
« Reply #1 on: February 20, 2017, 10:21:29 am »
You mean you want to use Property KeepConnection? Your question is not very clear to me, but it supports KeepConnection if that is what you want.
« Last Edit: February 20, 2017, 10:23:12 am by Thaddy »
Specialize a type, not a var.

valerife

  • New Member
  • *
  • Posts: 10
Re: fcl-web/fphttpclient multiple queries
« Reply #2 on: February 20, 2017, 10:26:27 am »
Yes i would like to use a property that allow me to keepConnection to be able to do multiples queries to my server. I looked again at fphttpclient.pp (/usr/share/fpc/3.0.0/..../fphttpclient) however i didn t find any property similar as keepconnection. 

Should i change my version of fpc src ? To have the latest release of fphttpclient ?

Thank you.
« Last Edit: February 20, 2017, 10:28:56 am by valerife »

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: fcl-web/fphttpclient multiple queries
« Reply #3 on: February 20, 2017, 11:02:12 am »
Yes i would like to use a property that allow me to keepConnection to be able to do multiples queries to my server. I looked again at fphttpclient.pp (/usr/share/fpc/3.0.0/..../fphttpclient) however i didn t find any property similar as keepconnection. 

Should i change my version of fpc src ? To have the latest release of fphttpclient ?

Thank you.

Code: Pascal  [Select][+][-]
  1. //starting from about line 300-305
  2.   TFPHTTPClient = Class(TFPCustomHTTPClient)
  3.   Published
  4.     Property KeepConnection;  // <----- what's this?
  5.     Property Connected;
  6.     Property IOTimeout;
  7.     Property RequestHeaders;
  8.     Property RequestBody;
  9.     Property ResponseHeaders;
  10.     Property HTTPversion;
  11.     Property ServerHTTPVersion;
  12.     Property ResponseStatusCode;
  13.     Property ResponseStatusText;
  14.     Property Cookies;
  15.     Property AllowRedirect;
  16.     Property MaxRedirects;
  17.     Property OnRedirect;
  18.     Property UserName;
  19.     Property Password;
  20.     Property OnPassword;
  21.     Property OnDataReceived;
  22.     Property OnHeaders;
  23.     Property OnGetSocketHandler;
  24.     Property Proxy;
  25.   end

I would suggest to upgrade to at least 3.0.2. Because that is the official release as it stands.

[edit]
The KeepConnection property is not yet in 3.0.2. Sorry. Only in trunk. It is possible, though, to use that package from trunk in 3.0.2 without change.
« Last Edit: February 20, 2017, 11:10:58 am by Thaddy »
Specialize a type, not a var.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: fcl-web/fphttpclient multiple queries
« Reply #4 on: February 20, 2017, 11:10:51 am »
I would suggest to upgrade to at least 3.0.2. Because that is the official release as it stands.
Thaddy, are you sure the KeepConnection is in 3.0.2???? (ok, you've already corrected that :) )
It's not as far as I can see.

KeepConnection is added on 11 november 2016 in trunk revision 34875.

Code: [Select]
Revision: 34875
Author: michael
Date: vrijdag 11 november 2016 13:28:44
Message:
* Added KeepConnection by Silvio Clecio (Bug ID 30788)
----
Added : /trunk/packages/fcl-web/examples/httpclient/keepalive.lpi
Added : /trunk/packages/fcl-web/examples/httpclient/keepalive.pp
Modified : /trunk/packages/fcl-web/src/base/fphttpclient.pp
(and http://bugs.freepascal.org/view.php?id=30788)

So I think it will be in 3.2.0.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: fcl-web/fphttpclient multiple queries
« Reply #5 on: February 20, 2017, 11:11:45 am »
You were too quick. I corrected my answer. It didn't make the back-port.
Specialize a type, not a var.

valerife

  • New Member
  • *
  • Posts: 10
Re: fcl-web/fphttpclient multiple queries
« Reply #6 on: February 20, 2017, 11:14:16 am »
In the meanwhile of upgrading all my sources i will create and free an FPHTTPClient object for each requests.

Thank you  very much for all your  fast answer !  :)

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: fcl-web/fphttpclient multiple queries
« Reply #7 on: February 20, 2017, 11:40:37 am »
So I think it will be in 3.2.0.
It is simply not always feasable for me to quickly check against sourcecode from the RTL.

And... I guess the next release will be 4.0. I very much doubt if there will be a point release for 3. That (3.0.2.) has already a good many back-ports and some of the language changes in trunk are too intrusive.
Specialize a type, not a var.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: fcl-web/fphttpclient multiple queries
« Reply #8 on: February 20, 2017, 11:58:46 am »
I checked it directly through the web interface for svn.
http://svn.freepascal.org/svn/fpc/tags/release_3_0_2/packages/fcl-web/src/base/fphttpclient.pp

So you could check rather quickly through http://svn.freepascal.org/svn/fpc/ what version has what.

I saw in my own trunk/log that it was added in november 2016 and understandably this was not added as a critical addition for 3.0.2. According to the bugtrack it is added in 3.1.1 and as target version 3.2.0. But the 3.2.0 is probably because the mantis system requires a target number so 3.2.0 was chosen, but indeed, it doesn't mean that version will see the light of day :)

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: fcl-web/fphttpclient multiple queries
« Reply #9 on: February 20, 2017, 12:06:58 pm »
That's what I usually do too. But I also need to check against what's on my disk. Sometimes I just assume my knowledge is current. That's correct..
Note that Mantis already has entries that resolve to 4.0..... I can't select it, but they are there...  8-)
Specialize a type, not a var.

 

TinyPortal © 2005-2018