Page 1 of 1
Get Body from Request Response
Posted: Fri Mar 08, 2019 9:56 am
by Albus
Hi, we're making Post-Requests with the LoadRequest method and then we retrieve the response with the OnResourceResponse Event. This is working fine. But now we need the Body of the response, but we couldn't see such a property on the ICefResponse variable. How can we get the body of the response?
Re: Get Body from Request Response
Posted: Fri Mar 08, 2019 10:41 am
by salvadordf
Use a URLRequest to get the body.
The URLRequest demo shows how to use a TCEFUrlRequestClientComponent and how to send GET and POST requests.
Read all the code comments for more information.
The most important thing to do while using URLRequests is to cancel all of them before closing your app to avoid crashes.
Re: Get Body from Request Response
Posted: Fri Mar 08, 2019 11:38 am
by Albus
Thank you. I saw that there is in addition to the TCefUrlRequestClientComponent a TCustomCefUrlrequestClient class. Can I use this instead also? Because I only need this RequestClient in the code, not on the GUI
Re: Get Body from Request Response
Posted: Fri Mar 08, 2019 1:34 pm
by salvadordf
That's possible but then it's more complicated to use because the URLRequest needs to be created in a CEF thread and TCefUrlRequestClientComponent handles all URLRequest events more easily.
TCefUrlRequestClientComponent inherits from TComponent and it doesn't have any GUI elements.
Re: Get Body from Request Response
Posted: Fri Mar 08, 2019 1:38 pm
by Albus
Ok, than we should use the component.
Then I have one more question: In the demo your making in the RequestComplete event a PostMessage. Why do you do this and is it nessacary? Is this to leave the cef thread?
Re: Get Body from Request Response
Posted: Fri Mar 08, 2019 1:59 pm
by salvadordf
All TCEFUrlRequestClientComponent events are executed in a CEF thread. I should have used a critical section every time I read or write to the TMemoryStream and I should have used more messages to update the GUI with the request status.
I try to keep all demos as simple as possible and sometimes I omit some messages or synchronization objects.
If you don't have any GUI element showing status information about this request then all you need is a way to tell the rest of your application that a request is completed and it's safe to use the downloaded data.