[Cannot add post in comments with code]
A test with Bing.com =>
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//this.Load += new System.EventHandler(this.Form1_Load); // Added in Designer
}
private bool bInitialized = false;
private async void button1_Click(object sender, EventArgs e)
{
if (bInitialized)
{
Microsoft.Web.WebView2.Core.CoreWebView2Environment webView2Environment = null;
string sTempWebCacheDir = System.IO.Path.GetTempPath();
webView2Environment = await Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync(null, sTempWebCacheDir, null);
//string sHeaders = "accept: application/json";
System.IO.Stream stm = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(""));
//Microsoft.Web.WebView2.Core.CoreWebView2WebResourceRequest wrr = webView2Environment.CreateWebResourceRequest("https://httpbin.org/post", "POST", stm, sHeaders);
string sHeaders = "Accept-Encoding gzip, deflate, br";
Microsoft.Web.WebView2.Core.CoreWebView2WebResourceRequest wrr = webView2Environment.CreateWebResourceRequest("https://www.bing.com", "GET", stm, sHeaders);
Microsoft.Web.WebView2.Core.CoreWebView2 cwv2 = webView21.CoreWebView2;
cwv2.NavigateWithWebResourceRequest(wrr);
}
}
private void Form1_Load(object sender, EventArgs e)
{
webView21.Source = new System.Uri("about:blank", System.UriKind.Absolute);
webView21.CoreWebView2InitializationCompleted += new System.EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs>(webView21_CoreWebView2InitializationCompleted);
}
private void webView21_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
{
bInitialized = true;
webView21.CoreWebView2.NavigationCompleted += webView21_NavigationCompleted;
webView21.CoreWebView2.AddWebResourceRequestedFilter("*", Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext.All);
webView21.CoreWebView2.WebResourceRequested += webView21_WebResourceRequested;
webView21.CoreWebView2.WebResourceResponseReceived += webView21_WebResourceResponseReceived;
}
private void webView21_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
{
System.Diagnostics.Debug.Print("NavigationCompleted");
}
private void webView21_WebResourceRequested(object sender, Microsoft.Web.WebView2.Core.CoreWebView2WebResourceRequestedEventArgs e)
{
System.Diagnostics.Debug.Print("WebResourceRequested");
System.Diagnostics.Debug.Print(e.Request.Uri);
// Add other Debug.Print...
}
private void webView21_WebResourceResponseReceived(object sender, Microsoft.Web.WebView2.Core.CoreWebView2WebResourceResponseReceivedEventArgs e)
{
System.Diagnostics.Debug.Print("WebResourceResponseReceived");
// Add other Debug.Print...
}
}