1、安装引用WebView2
1)使用Nuget界面管理器
搜索"Microsoft.Web.WebView",在列表中找到它,点击 "安装"
相关文档:VS(Visual Studio)中Nuget的使用
2)使用Package Manager命令安装
PM> Install-Package Microsoft.Web.WebView2
3)使用.NET CLI命令安装
> dotnet add package Microsoft.Web.WebView2
2、执行GET请求
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,
"GET",stream, "Content-Type: text/html");
webView.CoreWebView2.NavigateWithWebResourceRequest(request);
stream.Close();
stream.Dispose();
3、执行POST请求
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();