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.

View Request.PostData to str

dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

View Request.PostData to str

Post by dilfich »

Hi!
Please, show an example of how to do it?
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: View Request.PostData to str

Post by salvadordf »

Hi,

Take a look at the PostDataInspector demo.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: View Request.PostData to str

Post by dilfich »

There not showing PostData :(
These data are how to see?
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: View Request.PostData to str

Post by salvadordf »

Hi,

The OnBeforeNavigation is handled in the GlobalCEFApp_OnBeforeNavigation procedure, inside the DPR file.

In that procedure you have the request with all the information you asked.

request.PostData.GetElements will give you a list of ICefPostDataElement interfaces which have the posted data.

Then you can use ICefPostDataElement.GetBytesCount and ICefPostDataElement.GetBytes to get the information from that element.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: View Request.PostData to str

Post by dilfich »

Correctly?

Code: Select all

  if (request = nil) then
    TempString := 'no request'
   else
    if (request.postdata = nil) then
      TempString := 'no postdata'
     else begin
      Plist := Request.postData.GetElements(Request.postData.GetCount);
      for i:=0 to Plist.Count-1 do
            PElement:= Plist[i] as ICefPostDataElement;
      TempString := 'postdata elements : ' + inttostr(PElement.GetBytesCount);
     end;
But as for the string, I just don't understand..?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: View Request.PostData to str

Post by salvadordf »

Use the TStringStream class with the TStringStream.WriteBuffer function.

I haven't tested this but you might have to set the right encoding when you create the TStringStream instance.
mike2k
Posts: 22
Joined: Wed Jan 24, 2018 2:56 pm

Re: View Request.PostData to str

Post by mike2k »

dilfich wrote: Sun Dec 03, 2017 8:10 pm Correctly?

Code: Select all

  if (request = nil) then
    TempString := 'no request'
   else
    if (request.postdata = nil) then
      TempString := 'no postdata'
     else begin
      Plist := Request.postData.GetElements(Request.postData.GetCount);
      for i:=0 to Plist.Count-1 do
            PElement:= Plist[i] as ICefPostDataElement;
      TempString := 'postdata elements : ' + inttostr(PElement.GetBytesCount);
     end;
But as for the string, I just don't understand..?
Hi dilfich,

Did you managed to get the POST as strings ?


EDIT:
I've found the solution

Code: Select all

SetLength(myAnsiString, PElement.GetBytesCount);
PElement.GetBytes(PElement.GetBytesCount, PAnsiChar(myAnsiString));
myAnsiString will have the POST data in it :)
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: View Request.PostData to str

Post by dilfich »

TShowPostDataInfo(const aPostData : ICefPostData);

Chromium1BeforeResourceLoad....
if request.Method = 'POST' then TShowPostDataInfo(Request.PostData);
Your design from the examples works fine! But how to see the response of POST request?
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: View Request.PostData to str

Post by dilfich »

To clarify, the POST request was made through JS or JONS of the page itself and in the browser itself through RetrieveText or RetrieveHTML response can not be obtained.
For example in procedure Chromium1ResourceResponse perhaps can be as the get the answer?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: View Request.PostData to str

Post by salvadordf »

Try the TChromium.OnResourceResponse event.

The MiniBrowser has the code that reads the response in TMiniBrowserFrm.Chromium1ResourceResponse which calls TMiniBrowserFrm.InspectResponse

I'm not 100% sure it will work with requests made from JavaScript.
Post Reply