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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Get Body from Request Response

Post Reply
Albus

Get Body from Request Response

Post 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?
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get Body from Request Response

Post 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.
Albus

Re: Get Body from Request Response

Post 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
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get Body from Request Response

Post 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.
Albus

Re: Get Body from Request Response

Post 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?
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get Body from Request Response

Post 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.
Post Reply