C#
using DotNetBrowser; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; /** * The sample demonstrates how to configure Browser instance to use custom proxy settings. * By default Browser instance uses system proxy settings. */ namespace ProxySample { class Program { static void Main(string[] args) { String dataDir = Path.GetFullPath("chromium-data"); BrowserContextParams contextParams = new BrowserContextParams(dataDir); // Browser will automatically detect proxy settings. // contextParams.ProxyConfig = new AutoDetectProxyConfig(); // Browser will not use a proxy server. // contextParams.ProxyConfig = new DirectProxyConfig(); // Browser will use proxy settings received from proxy auto-config (PAC) file. //contextParams.ProxyConfig = new URLProxyConfig("<pac-file-url>"); // Browser will use custom user's proxy settings. String proxyRules = "http=foo:80;https=foo:80;ftp=foo:80;socks=foo:80"; String exceptions = "<local>"; // bypass proxy server for local web pages contextParams.ProxyConfig = new CustomProxyConfig(proxyRules, exceptions); // Creates Browser instance with context configured to use specified proxy settings. Browser browser = BrowserFactory.Create(new BrowserContext(contextParams)); // Handle proxy authorization. browser.Context.NetworkService.NetworkDelegate = new MyNetworkDelegate(); } private class MyNetworkDelegate : DefaultNetworkDelegate { public override bool OnAuthRequired(AuthRequiredParams parameters) { // If proxy server requires login/password, provide it programmatically. if (parameters.IsProxy) { parameters.Username = "proxy-username"; parameters.Password = "proxy-password"; return false; } return true; } } } }
VB.NET
Imports DotNetBrowser Imports System.IO 'The sample demonstrates how to configure Browser instance to use custom proxy settings. 'By default Browser instance uses system proxy settings. Module ProxySample Sub Main(ByVal args As String()) Dim dataDir As String = Path.GetFullPath("chromium-data") Dim contextParams As BrowserContextParams = New BrowserContextParams(dataDir) ' Browser will automatically detect proxy settings. ' contextParams.ProxyConfig = New AutoDetectProxyConfig(); ' Browser will not use a proxy server. ' contextParams.ProxyConfig = New DirectProxyConfig(); ' Browser will use proxy settings received from proxy auto-config (PAC) file. 'contextParams.ProxyConfig = New URLProxyConfig("<pac-file-url>"); ' Browser will use custom user's proxy settings. Dim proxyRules As String = "http=foo:80;https=foo:80;ftp=foo:80;socks=foo:80" Dim exceptions As String = "<local>" contextParams.ProxyConfig = New CustomProxyConfig(proxyRules, exceptions) ' Creates Browser instance with context configured to use specified proxy settings. Dim browser As Browser = BrowserFactory.Create(New BrowserContext(contextParams)) ' Handle proxy authorization. browser.Context.NetworkService.NetworkDelegate = New MyNetworkDelegate() End Sub Private Class MyNetworkDelegate Inherits DefaultNetworkDelegate Public Overrides Function OnAuthRequired(ByVal parameters As AuthRequiredParams) As Boolean ' If proxy server requires login/password, provide it programmatically. If parameters.IsProxy Then parameters.Username = "proxy-username" parameters.Password = "proxy-password" Return False End If Return True End Function End Class End Module