Page 1 of 1

Re: response body (JSON)

Posted: Tue Feb 06, 2018 2:55 pm
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

Re: response body (JSON)

Posted: Tue Feb 06, 2018 3:51 pm
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.

Re: response body (JSON)

Posted: Wed Feb 07, 2018 9:03 am
by salvadordf
Thanks for the bug fix ! :D

I uploaded the fixed version to GitHub.

Re: response body (JSON)

Posted: Wed Feb 07, 2018 9:48 am
by salvadordf
I also added your code to control the stream size to send the STREAM_COPY_COMPLETE message.

Thanks again! :D

Re: response body (JSON)

Posted: Wed Feb 07, 2018 1:37 pm
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.

Re: response body (JSON)

Posted: Thu Feb 08, 2018 9:55 am
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.

Re: response body (JSON)

Posted: Thu Feb 08, 2018 11:51 am
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.

Re: response body (JSON)

Posted: Fri Oct 19, 2018 10:46 am
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:

Re: response body (JSON)

Posted: Mon Aug 17, 2020 1:21 pm
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>

Re: response body (JSON)

Posted: Thu Aug 27, 2020 2:05 pm
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.