Page 1 of 1

How do I can parse request.PostData?

Posted: Sat Jan 18, 2020 10:13 pm
by RedOctober
Hello,

is there any way to parse request.PostData in onBeforeResourceLoad as string? For example, to get something like this:

Code: Select all

aaa=111&bbb=222&ccc=333

Re: How do I can parse request.PostData?

Posted: Sun Jan 19, 2020 3:00 am
by RedOctober
I found this solution - hope it will help someone ;)

Code: Select all

procedure Chromium1GetResourceHandler(Sender: TObject; const browser: ICefBrowser;
const frame: ICefFrame; const request: ICefRequest; out Result: ICefResourceHandler);
var
AElements:ICefPostDataElement;
AStr:AnsiString;
begin
if Assigned(request.PostData) then
begin
AElements := ICefPostDataElement(request.PostData.GetElements(1)[0]);
if (AElements.GetType = TCefPostDataElementType.PDE_TYPE_BYTES)
or (AElements.GetType = TCefPostDataElementType.PDE_TYPE_FILE) then
begin
SetLength(AStr,AElements.GetBytesCount);
AElements.GetBytes(AElements.GetBytesCount,PChar(AStr));
end;
end;
end;

Re: How do I can parse request.PostData?

Posted: Sun Jan 19, 2020 9:39 am
by salvadordf
I'm glad you found the solution. :D

I was going to suggest the TForm1.HandlePostData procedure in the PostInspectorBrowser demo.

There's even a function to get the "key" and "value" pairs in the new uCEFOAuth2Helper.pas CEF4Delphi unit called ParseCodeRequestResponse.