HTTP is a request/response protocol. TIdHTTP
is designed to follow that protocol, and that means its request methods always read a response in full before exiting.
That being said, you have two options to accomplish what you want:
let TIdHTTP
read the response normally, but simply not save it anywhere. You can use a response TStream
that discards any bytes written to it (such as TIdEventStream
with no OnWrite
event handler), or if you are using an up-to-date version of Indy, you can simply set the response stream to NULL
.
IdHTTP1->Post(sURL, reqStream, (TStream*)NULL);
Obviously, this still has the overhead of reading the full response from the socket, at least.
use the TIdHTTP::OnHeadersAvailable
event to check the current Response
status code. When a final (non-redirect, non-authorization) status code is received, abort processing of the response by throwing an exception (such as by calling Sysutils::Abort()
), which will bypass reading the response body. Make sure to close the underlying socket after TIdHTTP::Post()
exits, if TIdHTTP
doesn't do it automatically for you. Or, you can close the socket instead of throwing your own exception, and let TIdHTTP
throw its own exception when it can't read the response body from the socket. The end effect is the same either way.
I have added a new feature request to Indy's issue tracker for you, to address this situation better in a future version of Indy:
#230 Add hoNoReadResponseBody flag to TIdHTTP.HTTPOptions property