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.

response body (JSON)

Post Reply
User avatar
salvadordf
Posts: 4575
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: response body (JSON)

Post by salvadordf »

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

Re: response body (JSON)

Post by salvadordf »

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

Re: response body (JSON)

Post by salvadordf »

Thanks for the bug fix ! :D

I uploaded the fixed version to GitHub.
User avatar
salvadordf
Posts: 4575
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: response body (JSON)

Post by salvadordf »

I also added your code to control the stream size to send the STREAM_COPY_COMPLETE message.

Thanks again! :D
User avatar
salvadordf
Posts: 4575
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: response body (JSON)

Post by salvadordf »

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

Re: response body (JSON)

Post by salvadordf »

Thanks again! :D

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.
mike2k
Posts: 22
Joined: Wed Jan 24, 2018 2:56 pm

Re: response body (JSON)

Post by mike2k »

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.
coater
Posts: 189
Joined: Sat Sep 29, 2018 1:51 pm

Re: response body (JSON)

Post by coater »

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/

Code: Select all

FRscSize: = StrToIntDef (response.GetHeader ('Content-Length'), 0);
FRscSize = 0
It is necessary to search for another method
try 'content-type' :lol:
fernandolfc
Posts: 1
Joined: Tue Aug 11, 2020 11:39 am

Re: response body (JSON)

Post by fernandolfc »

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>
resatarikan
Posts: 1
Joined: Sat Aug 08, 2020 5:44 pm

Re: response body (JSON)

Post by resatarikan »

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 :D
ResponseFilterBrowser2.zip
can i intercept xhr response with this example.
Post Reply