restdelphidelphi-10.2-tokyo

DELETE request with body from TRESTRequest


I know, that TRESTRequest is not designed to send body in DELETE requests. But these days many servers accept such requests.

Is there a way to somehow get around this component flaw?

For example, this can be done with TIdHTTP.

P.S. Indeed, TRESTRequest supports DELETE request with a body in Embarcadero Delphi version 10.3 and later. (version 10.2 and earlier - does not support)


Solution

  • I know, that TRESTRequest is not designed to send body in DELETE requests.

    Actually, it is designed that way, at least in Delphi 10.3 and later (I don't have Delphi 10.2 to check with).

    Is there a way to somehow get around this component flaw?

    Add an item to the TRESTRequest.Params property and set its Kind property to pkREQUESTBODY. You can store your body data in the item's Stream or Value property.

    Alternatively, you can use TRESTRequest.AddBody(), which will add a pkREQUESTBODY item to TRESTRequest.Params for you.