Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
Get Body from Request Response
Get Body from Request Response
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?
- salvadordf
- Posts: 4565
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Get Body from Request Response
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.
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
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
- salvadordf
- Posts: 4565
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Get Body from Request Response
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.
TCefUrlRequestClientComponent inherits from TComponent and it doesn't have any GUI elements.
Re: Get Body from Request Response
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?
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?
- salvadordf
- Posts: 4565
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Get Body from Request Response
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.
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.