自动填充代理要求 webview2

问题描述

我正在使用 winforms 和 webview2 创建自定义 Internet 浏览器,每当我在使用学校 Internet 时搜索某些内容时,它都会有一个代理框询问我的用户名和密码。 如何在每次打开时自动填充此框

解决方法

command-line options for proxy settings。您可以通过 AdditionalBrowserArguments 实例的 CoreWebView2EnvironmentOptions 属性设置这些选项,并在创建 CoreWebView2 时传递给 CoreWebView2Environment.CreateAsync

例如:

WebView2 webView21 = new Microsoft.Web.WebView2.WinForms.WebView2();
private async void Form1_Load(object sender,EventArgs e)
{
    var options = new CoreWebView2EnvironmentOptions();
    options.AdditionalBrowserArguments = "--proxy-server=\"proxyhostname:8000\"";
    var env = await CoreWebView2Environment.CreateAsync(null,null,options);
    await webView21.EnsureCoreWebView2Async(env);

    webView21.Dock = DockStyle.Fill;
    this.Controls.Add(webView21);
    webView21.Source = new Uri("Https://stackoverflow.com");
}

以下是您可以使用的选项:

  • --no-proxy-server:不使用代理。
  • --proxy-auto-detect:自动检测代理配置。
  • --proxy-server=<scheme>=<uri>[:<port>][;...] | <uri>[:<port>] | "direct://":使用自定义配置。
  • --proxy-bypass-list=(<trailing_domain>|<ip-address>)[:<port>][;...]:为指定的以分号分隔的主机列表绕过任何指定的代理。
  • --proxy-pac-url=<pac-file-url>:使用指定 URL 处的 PAC 文件。

要查看有关这些选项的更多说明和示例,请参阅: