CoreWebView2.NavigateWithWebResourceRequest Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Navigates using a constructed CoreWebView2WebResourceRequest object.
public void NavigateWithWebResourceRequest (Microsoft.Web.WebView2.Core.CoreWebView2WebResourceRequest Request);
member this.NavigateWithWebResourceRequest : Microsoft.Web.WebView2.Core.CoreWebView2WebResourceRequest -> unit
Public Sub NavigateWithWebResourceRequest (Request As CoreWebView2WebResourceRequest)
Parameters
- Request
- CoreWebView2WebResourceRequest
The constructed web resource object to provide post data or additional request headers during navigation.
Examples
// Prepare post data as UTF-8 byte array and convert it to stream
// as required by the application/x-www-form-urlencoded Content-Type
var dialog = new TextInputDialog(
title: "NavigateWithWebResourceRequest",
description: "Specify post data to submit to https://www.w3schools.com/action_page.php.");
if (dialog.ShowDialog() == true)
{
string postDataString = "input=" + dialog.Input.Text;
UTF8Encoding utfEncoding = new UTF8Encoding();
byte[] postData = utfEncoding.GetBytes(
postDataString);
MemoryStream postDataStream = new MemoryStream(postDataString.Length);
postDataStream.Write(postData, 0, postData.Length);
postDataStream.Seek(0, SeekOrigin.Begin);
CoreWebView2WebResourceRequest webResourceRequest =
WebViewEnvironment.CreateWebResourceRequest(
"https://www.w3schools.com/action_page.php",
"POST",
postDataStream,
"Content-Type: application/x-www-form-urlencoded\r\n");
_iWebView2.CoreWebView2.NavigateWithWebResourceRequest(webResourceRequest);
}
Remarks
The headers in the CoreWebView2WebResourceRequest override headers added by WebView2 runtime except for Cookie headers. Method can only be either GET
or POST
. Provided post data will only be sent only if the method is POST
and the uri scheme is HTTP(S)
.