webview2抓取返回数据

webview2设置过滤器

            //进行网址过滤
            //webView.CoreWebView2.AddWebResourceRequestedFilter("http://test.com:8080/xx", CoreWebView2WebResourceContext.All);
            webView.CoreWebView2.WebResourceResponseReceived += CoreWebView2_WebResourceResponseReceivedAsync;

解析返回值


 private async void CoreWebView2_WebResourceResponseReceivedAsync(object sender, CoreWebView2WebResourceResponseReceivedEventArgs e)
 {
     if (e.Response != null && e.Response.StatusCode == 200)
     {
         if (e.Request.Uri.Contains("/test/gettest"))
         {

             Stream content = await e.Response.GetContentAsync();
             StreamReader sr = new StreamReader(content, System.Text.Encoding.UTF8);
             string jsonText = sr.ReadToEnd();
           
         }
        
     }
 }
posted @ 2024-11-29 19:43  Hey,Coder!  阅读(43)  评论(0编辑  收藏  举报