[fpc-pascal] Cannot reuse TFPHTTPClient object for 2 different POST requests
Michael Van Canneyt
michael at freepascal.org
Sun Jan 18 17:52:03 CET 2015
On Sun, 18 Jan 2015, leledumbo wrote:
>> i was thinking that there's some sort of inbound traffic that may be
> filling a
> buffer that needs to be emptied... i don't know or have any other ideas to
> Mmm...could be, that's what should be searched for.
>> The problem is not in TFPHTTPClient. The problem is the data and/or URL
>> for request 3:
> OK, now try creating a new TFPHTTPClient instance for each request, don't
> reuse. It should work as it's my current workaround, but I think it's a
> waste of resource. Can you explain that?
Yes, I can. The TFPHTTPClient instance is not stateless.
Before doing a call, some headers are added to the request headers if they are not there yet.
For example, the Content-Size header.
But the Content-Size header is not added if is already present.
For calls 1 and 2 it does not matter, since the size is the same.
For the third call, however, it does matter, since the content-size header still contains the size of call 2 (93),
which does not match the size of call 3: call 3 has less data (57).
So the server is waiting for more data (it expects 93 bytes as indicated in Content-Size instead of 57 actually present).
The solution is simple: Try clearing the headers before doing your calls.
etc. then it will work. (it does here)
More information about the fpc-pascal