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.
raychl
Posts: 4 Joined: Mon Nov 25, 2019 7:00 am
Post
by raychl » Wed Mar 02, 2022 3:53 am
C# has an example:
Code: Select all
var postData = "thing1=hello";
postData += "&thing2=world";
var data = Encoding.ASCII.GetBytes(postData);
MemoryStream stream = new MemoryStream();
stream.Write(data, 0, data.Length);
var request = webView.CoreWebView2.Environment.CreateWebResourceRequest(navigateData.Url,
"POST", stream, "Content-Type: application/x-www-form-urlencoded");
webView.CoreWebView2.NavigateWithWebResourceRequest(request);
stream.Close();
stream.Dispose();
ICoreWebView2Environment does not have CreateWebResourceRequest。。
raychl
Posts: 4 Joined: Mon Nov 25, 2019 7:00 am
Post
by raychl » Wed Mar 02, 2022 9:41 am
I use the following code, but sometimes it throw a pointer access exception.
Code: Select all
procedure TBrowserFrame.PostDataByWVB;
var
ARequest:ICoreWebView2WebResourceRequest;
AStream:TMemoryStream;
AIStream : IStream;
AResult:Boolean;
begin
AStream:=TStringStream.Create('key1=111&key2=123');
AIStream:=TStreamAdapter.Create(AStream,soReference);
AResult:=False;
try
AResult:=WVBrowser1.CoreWebView2Environment.CreateWebResourceRequest(URLCbx.Text,'POST',AIStream,'Content-Type: application/x-www-form-urlencoded',ARequest);
if (AResult) then
begin
AResult:=WVBrowser1.NavigateWithWebResourceRequest(ARequest);
end;
finally
AStream.Free;
AIStream._Release;
end;
end;
salvadordf
Posts: 4620 Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:
Post
by salvadordf » Thu Mar 03, 2022 10:38 am
I'll try to include a NavigateWithWebResourceRequest example in the next webView4Delphi update.
salvadordf
Posts: 4620 Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:
Post
by salvadordf » Fri Mar 04, 2022 4:49 pm
I just uploaded the new NavigateWithWebResourceRequestBrowser demo.
Download WebView4Delphi from GitHub to see it.