我正在尝试使用 WebView2 并获取服务器响应代码。但是 CoreWebView2WebResourceRequestedEventArgs.Response 由于某种原因始终为空:
webView.CoreWebView2Ready += CoreWebView2Ready;
private void CoreWebView2Ready(object sender, EventArgs e)
{
webView.CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All);
webView.CoreWebView2.WebResourceRequested += WebResourceRequested;
}
private void WebResourceRequested(object sender, CoreWebView2WebResourceRequestedEventArgs e)
{
/* e.Response is always null for some reason */
if (e.Response != null)
{
int statusCode = e.Response.StatusCode;
string header = e.Response.Headers.GetHeader("myheader");
}
}
如何获取响应码?