Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To handle POST data in the OnNavigate event when using Delphi TEdgeBrowser, you can use the following steps:

  1. Retrieve the web request data by accessing the WebRequest interface of the EdgeBrowser.
  2. Check if the request method is POST.
  3. If the request method is POST, retrieve the form data by accessing the POST data from the IRequestData interface.
  4. Process the form data as necessary.

Here is an example code snippet:

procedure TForm1.EdgeBrowser1Navigate(Sender: TObject; const Browser: IDispatch; const frame: IDispatch; const url: OleVariant);
var
  WebRequest: ICoreWebView2WebResourceRequest;
  RequestData: IRequestData;
  RequestDataAsStream: IRandomAccessStream;
  Reader: IInputStream;
  Buffer: TBytes;
  Charset: string;
begin
  EdgeBrowser1.CoreWebView2.Environment.GetWebResourceRequest(Browser, url, @WebRequest);
  if WebRequest <> nil then
  begin
    if WebRequest.Method = 'POST' then
    begin
      RequestData := WebRequest.PostData;
      if RequestData <> nil then
      begin
        RequestDataAsStream := RequestData.GetAsync().GetResults();
        Reader := TDataReader.Create(RequestDataAsStream);
        SetLength(Buffer, RequestDataAsStream.Size);
        Reader.Read(Buffer, Length(Buffer), @Length(Buffer));
        Charset := RequestData.Headers.GetValue('Content-Type').Split([';'])[1].Split(['='])[1];
        // Process the form data as necessary
      end;
    end;
  end;
end;

Note that you may need to adjust the code based on your specific requirements and the structure of the POST data.