Indy's TIdHttp
class has - in a recent version - a Delete()
routine. But for some reason, this is a procedure, not a function. Put()
, Get()
, etc. are all functions that return the content of the response body. Either as a string or have it delivered to a TStream
. This is not possible with Delete()
, which is contradictory to DELETE
's definition:
A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.
Source.
I then tried using GetResponse()
, but that instead simply closed my connection gracefully, without filling in the response.
So how do I read the contents of the response body from a DELETE response?
You need to update your Indy installation. Overloads for getting DELETE
method responses were added in September 2013 in SVN revision 5056 for this feature request:
Add overloads for TIdHTTP Delete() and Options() methods that can output a response's message body
If you don't want to update Indy for some reason, you can subclass the TIdHTTP
component and add a method that will pass a response stream to the DoRequest
method, e.g.:
type
TIdHTTP = class(IdHTTP.TIdHTTP)
public
procedure DeleteEx(AURL: string; AResponseContent: TStream);
end;
implementation
{ TIdHTTP }
procedure TIdHTTP.DeleteEx(AURL: string; AResponseContent: TStream);
begin
DoRequest(Id_HTTPMethodDelete, AURL, nil, AResponseContent, []);
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With