0

How can I send a POST request with Indy (10) and then ignore the result(s) or lowlevel API recv? I'm asking because I do not need the results and I would like to save bandwidth.

Benjamin Weiss
  • 3,206
  • 2
  • 37
  • 87
  • 2
    Done. It would be better in the future if you are more careful with your questions and be specific with them, so that the comments and downvotes don't get there in the first place. (We shouldn't have to fix your questions in order to save you from closure or downvotes, if you put more effort into asking them in the first place.) :-) – Ken White May 15 '13 at 03:14
  • 1
    Removed my downvote and comment, but cannot remove my close vote. You do need to be careful how you word your question, because you get exactly what you ask. – Jerry Dodge May 15 '13 at 03:30
  • 1
    I'm not sure that I understand the question. Do you want to use Post() function asynchronously and not wait for it to return result? If so, I doubt that is possible with Indy, only way that I see is to execute IdHTTP.Post() in separate thread, or to go with another component that can do async post (e.g. ICS: [link](http://www.overbyte.be)) – Marko Paunovic May 15 '13 at 03:31
  • @MarkoPaunovic this would be a workaround, but I'm asking in a manner of bandwith waste. – Benjamin Weiss May 15 '13 at 03:43
  • 1
    Hmm, I doubt thats possible with existing components, atleast the ones I know for. Check this [link](http://stackoverflow.com/questions/1823542/how-to-send-a-http-post-request-in-delphi-using-wininet-api) and the code in answer. Try to strip the part where he waits for response after sending request. – Marko Paunovic May 15 '13 at 03:56
  • I think this question essentially asks to complete this analogy: `GET : HEAD :: POST : ___`. – Rob Kennedy May 15 '13 at 04:07
  • 1
    Is the server yours? Are you able to modify the code of the server? Because if so, the easy solution is to not send back anything in the first place. But chances are it's not yours. – Jerry Dodge May 15 '13 at 04:16
  • Not the server is not mine and it's https. Since I know all the POST parameters I don't need get before. Thanks for your tips tho. – Benjamin Weiss May 15 '13 at 05:18

1 Answers1

2

When using TIdHTTP, you cannot ignore the recv(), but you can ignore the response data, at least. Call the overloaded version of Post() that takes a AResponseContent: TStream parameter as output, and set the TStream to nil. TIdHTTP will still read the response headers and body data from the socket, but it will discard whatever it reads for the body. This is important if HTTP keep-alives are used, as it keeps the connection in sync so subsequent HTTP requests can continue being sent on the same connection. If you are not using HTTP keep-alives, then the connection will be closed before Post() exits. If you want to close the connection sooner, you can try raising an exception in the TIdHTTP.OnWork event when AWorkMode is wmRead, but that may not work very well, especially if HTTP redirects are used.

If you just want to send a POST request and ignore the response completely, you are better off using TIdTCPClient instead and just send your own POST request manually and then close the connection immediately.

Remy Lebeau
  • 454,445
  • 28
  • 366
  • 620