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.
response body (JSON)
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: response body (JSON)
Hi,
Please, be more specific. There are many examples about using the JSON parser in Delphi.
Search Delphi json in google or your favorite search engine and you will find many examples.
Delphi can handle JSON data. Read this :
http://docwiki.embarcadero.com/RADStudio/Tokyo/en/JSON
Please, be more specific. There are many examples about using the JSON parser in Delphi.
Search Delphi json in google or your favorite search engine and you will find many examples.
Delphi can handle JSON data. Read this :
http://docwiki.embarcadero.com/RADStudio/Tokyo/en/JSON
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: response body (JSON)
Hi,
I found this GeoIP JSON example :
https://www.sitepoint.com/geoip-json-example/
If you open this URL in the SimpleBrowser2 demo you will see the the JSON contents in the browser as text :
http://ip-api.com/json/54.148.84.95
Then you can get the JSON text using the TChromium.RetrieveText function and receive the text content in the TChromium.OnTextResultAvailable event.
Then you can parse the JSON file in Delphi using this :
http://docwiki.embarcadero.com/RADStudio/Tokyo/en/JSON
If you prefer to download the JSON file you can also call TChromium.StartDownload
If your web page loads a JSON resource file you can use the ResponseFilterBrowser demo to get the JSON file contents.
I found this GeoIP JSON example :
https://www.sitepoint.com/geoip-json-example/
If you open this URL in the SimpleBrowser2 demo you will see the the JSON contents in the browser as text :
http://ip-api.com/json/54.148.84.95
Then you can get the JSON text using the TChromium.RetrieveText function and receive the text content in the TChromium.OnTextResultAvailable event.
Then you can parse the JSON file in Delphi using this :
http://docwiki.embarcadero.com/RADStudio/Tokyo/en/JSON
If you prefer to download the JSON file you can also call TChromium.StartDownload
If your web page loads a JSON resource file you can use the ResponseFilterBrowser demo to get the JSON file contents.
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: response body (JSON)
Thanks for the bug fix !
I uploaded the fixed version to GitHub.

I uploaded the fixed version to GitHub.
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: response body (JSON)
I also added your code to control the stream size to send the STREAM_COPY_COMPLETE message.
Thanks again!
Thanks again!

- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: response body (JSON)
I uploaded a revised version that sets FRscSize to -1 in case the server doesn't send that header.
CEF should send a data_in = nil in the Filter_OnFilter event when there's no more data and that should be enough to detect when you can handle the stream.
CEF should send a data_in = nil in the Filter_OnFilter event when there's no more data and that should be enough to detect when you can handle the stream.
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: response body (JSON)
Thanks again!
I added most of your code to the demo. I still keep setting aResult in Filter_OnFilter as indicated by the CEF3 code comments but using TChromium.OnResourceLoadComplete is a good solution when the server doesn't send a Content-Length header or CEF doesn't send a data_in = nil in Filter_OnFilter.

I added most of your code to the demo. I still keep setting aResult in Filter_OnFilter as indicated by the CEF3 code comments but using TChromium.OnResourceLoadComplete is a good solution when the server doesn't send a Content-Length header or CEF doesn't send a data_in = nil in Filter_OnFilter.
Re: response body (JSON)
I personally use my custom TCefResponseFilter with TMemoryStream and URL members, which are created/initialized on filter create and in destroy I get the whole response data in the TMemoryStream and pass it to main thread with postmessage for processing
So I don't have any global variable, all is done in my custom TCefResponseFilter.

Re: response body (JSON)
try 'content-type'sts wrote: Wed Feb 07, 2018 12:01 pm bad news:
GetHeader ('Content-Length') - does not work on all sites (or not always?)
at https://www.wikipedia.org/It is necessary to search for another methodCode: Select all
FRscSize: = StrToIntDef (response.GetHeader ('Content-Length'), 0); FRscSize = 0

-
- Posts: 1
- Joined: Tue Aug 11, 2020 11:39 am
Re: response body (JSON)
Hello! I'm using chromium to get the full site as soon as it has just been loaded, via the response, so that I wouldn't have to use the GetSource method, but the full source doesn't come, now it comes complete and sometimes it is missing part of the beginning of the html, What can it be?
An example site is msn.com
Site starts:
<! DOCTYPE html> <html prefix = "og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#" lang = "en-BR" style = "font-size : 62.5% "class =" hiperf "dir =" ltr ">
However, it only returns from:
l = f & amp; f = jpg & quot;} "src =" // static-global-s-msn-com.akamaized.net/hp-eus/sc/9b/e151e5.gif "/> <h3> Follow the & # 250; latest news about coronavirus </h3>
</div>
</a>
An example site is msn.com
Site starts:
<! DOCTYPE html> <html prefix = "og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#" lang = "en-BR" style = "font-size : 62.5% "class =" hiperf "dir =" ltr ">
However, it only returns from:
l = f & amp; f = jpg & quot;} "src =" // static-global-s-msn-com.akamaized.net/hp-eus/sc/9b/e151e5.gif "/> <h3> Follow the & # 250; latest news about coronavirus </h3>
</div>
</a>
-
- Posts: 1
- Joined: Sat Aug 08, 2020 5:44 pm
Re: response body (JSON)
can i intercept xhr response with this example.sts wrote: Thu Feb 08, 2018 8:32 am Hello salvadordf !
I looked again Filter_OnFilter
It's still easier: you do not even need to use aResult (all the pieces of the answer will come)
and the end of the resource load can be controlled in the ResourceLoadComplete![]()
ResponseFilterBrowser2.zip