Colek 0 Posted April 6, 2020 Hello, I am working with a rather unstable API. Sometimes, I'm getting an error 404 or 403 without a reason, but simply retrying the request the second time works and I'm receiving proper data from API. I would like to implement a feature, where if my THttpCli gets in header one of these codes, I will retry the request. But I am unsure on how to retry the request from, for example, OnHeaderEnd. What code should I implement in this procedure to retry the request? Sending a simple GetAsync again doesn't seem to work. Thank you, Piotr Share this post Link to post
Fr0sT.Brutal 900 Posted April 6, 2020 You should finish the call chain in OnHeaderEnd and retry the request async-ly. F.ex., by posting a custom message via PostMessage to socket control's handle (and, of course, write handler for it). Also don't forget to limit number of retries Share this post Link to post
Colek 0 Posted April 6, 2020 53 minutes ago, Fr0sT.Brutal said: You should finish the call chain in OnHeaderEnd and retry the request async-ly. F.ex., by posting a custom message via PostMessage to socket control's handle (and, of course, write handler for it). Also don't forget to limit number of retries Thank you for the very quick reply, appreciated! Is there a chance you could write a code snippet that would show how can I achieve that? I don't really understand how to do this myself. I'm not an experienced programmer. Thank you, Piotr Share this post Link to post
Fr0sT.Brutal 900 Posted April 6, 2020 Sorry, I have no Delphi nearby currently, try to read ICS samples, there are plenty. Share this post Link to post
Angus Robertson 574 Posted April 6, 2020 Where ever you check the 404 error send the windows message to start another GetAsync request. Or use sync methods when you can do a simple loop and break when it works, Get instead of GetAsync it all depends on how your application designed. Angus Share this post Link to post
FPiette 382 Posted April 6, 2020 Colek, I would create a new component instead of modifying the ICS one. You can either inherit from THttpCli component or inherit from TComponent and embed a THppCli to do what needs to be done. Either way has pros and cons but both are exactly what object oriented programming is all about. Think about moving the logic behind your application into a component instead of putting it into a TForm. Share this post Link to post
Colek 0 Posted April 6, 2020 Thank you for your suggestions and help! 🙂 In the end, I did make an inherited class from the THttpCli and I am checking the status codes in OnRequestDone event and handling it there. Everything works as I wanted it to 🙂 Thanks again, Piotr Share this post Link to post