예제 #1
0
        void NavigateWithWebResourceRequestCmdExecuted(object target, ExecutedRoutedEventArgs e)
        {
            // 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");
                webView.CoreWebView2.NavigateWithWebResourceRequest(webResourceRequest);
            }
        }