[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-post-de-csharp-http-proxy-guide-2024":3},{"success":4,"payload":5,"related":70,"errors":164},true,{"id":6,"slug":7,"title":8,"excerpt":9,"body_html":10,"meta_title":11,"meta_description":12,"canonical_url":13,"canonical_override":14,"og_title":15,"og_description":16,"og_image_url":17,"faq_json":18,"key_takeaways":34,"allow_index":40,"noindex_google_only":40,"allow_follow":4,"published_at":41,"updated_at":41,"content_updated_at":42,"featured_image_url":17,"featured_image_alt":14,"card_image_url":14,"reading_time_minutes":43,"author":44,"categories":48,"tags":55,"alternates":56,"locale_paths":61,"views":69},64,"csharp-http-proxy-guide-2024","C# HTTP Proxy mit .NET 8+: Der ultimative Guide für Entwickler","Lernen Sie, wie Sie HTTP-Proxys in C# und .NET 8+ konfigurieren: von HttpClient über SocketsHttpHandler bis hin zu rotierenden Proxy-Pools mit Polly und Dependency Injection.","\u003Ch2>Warum C# HTTP Proxy-Konfiguration wichtig ist\u003C\u002Fh2>\u003Cp>Wenn Sie als .NET-Entwickler Web-Scraping, API-Automatisierung oder Preisüberwachung betreiben, kommen Sie an Proxys nicht vorbei. Websites erkennen und blockieren verdächtige Anfragemuster – und eine einzelne IP-Adresse, die hunderte Requests pro Minute sendet, ist definitiv verdächtig.\u003C\u002Fp>\u003Cp>Die Verwendung von C# HTTP Proxys mit HttpClient ist nicht trivial. Es gibt Fallstricke bei Connection-Pooling, DNS-Resolution, TLS-Zertifikaten und Proxy-Rotation. Dieser Guide zeigt Ihnen, wie Sie \u003Cstrong>.NET HttpClient mit Proxy\u003C\u002Fstrong> korrekt konfigurieren und produktionsreife Lösungen für \u003Cstrong>C# residential proxies\u003C\u002Fstrong> implementieren.\u003C\u002Fp>\u003Ch2>Grundlagen: HttpClient mit WebProxy\u003C\u002Fh2>\u003Cp>Der klassische Weg in .NET verwendet \u003Ccode>HttpClientHandler\u003C\u002Fcode> mit einem \u003Ccode>WebProxy\u003C\u002Fcode>-Objekt. Das funktioniert für einfache Szenarien, hat aber einige Eigenheiten, die Sie kennen müssen.\u003C\u002Fp>\u003Cpre>\u003Ccode>using System.Net;\nusing System.Net.Http;\n\n\u002F\u002F Proxy mit Credentials konfigurieren\nvar proxy = new WebProxy(&quot;http:\u002F\u002Fgate.proxyhat.com:8080&quot;)\n{\n    Credentials = new NetworkCredential(&quot;user-country-US&quot;, &quot;your-password&quot;),\n    BypassProxyOnLocal = true,\n    BypassList = new[] { &quot;localhost&quot;, &quot;127.0.0.1&quot;, &quot;*.internal.local&quot; }\n};\n\n\u002F\u002F HttpClientHandler mit Proxy erstellen\nvar handler = new HttpClientHandler\n{\n    Proxy = proxy,\n    UseProxy = true,\n    UseDefaultCredentials = false,\n    AllowAutoRedirect = true,\n    MaxAutomaticRedirections = 5\n};\n\n\u002F\u002F HttpClient instanziieren (als Singleton verwenden!)\nvar client = new HttpClient(handler)\n{\n    Timeout = TimeSpan.FromSeconds(30)\n};\n\n\u002F\u002F Request senden\nvar response = await client.GetAsync(&quot;https:\u002F\u002Fhttpbin.org\u002Fip&quot;);\nvar content = await response.Content.ReadAsStringAsync();\nConsole.WriteLine($&quot;Response: {content}&quot;);\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>\u003Cstrong>Wichtig:\u003C\u002Fstrong> Instanziieren Sie \u003Ccode>HttpClient\u003C\u002Fcode> nicht pro Request. Das führt zu Socket-Exhaustion. Verwenden Sie \u003Ccode>IHttpClientFactory\u003C\u002Fcode> oder einen Singleton.\u003C\u002Fp>\u003Ch3>Proxy-URL-Format mit ProxyHat\u003C\u002Fh3>\u003Cp>Bei ProxyHat können Sie Geo-Targeting und Session-Flags direkt im Benutzernamen übergeben:\u003C\u002Fp>\u003Cpre>\u003Ccode>\u002F\u002F US-IP mit Session-Sticky\nvar proxy = new WebProxy(&quot;http:\u002F\u002Fgate.proxyhat.com:8080&quot;)\n{\n    Credentials = new NetworkCredential(&quot;user-country-US-sid-abc123&quot;, &quot;your-password&quot;)\n};\n\n\u002F\u002F Deutsche IP aus Berlin\nvar proxyDe = new WebProxy(&quot;http:\u002F\u002Fgate.proxyhat.com:8080&quot;)\n{\n    Credentials = new NetworkCredential(&quot;user-country-DE-region-state_of_berlin-city-berlin&quot;, &quot;your-password&quot;)\n};\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>SocketsHttpHandler: Der moderne Ansatz\u003C\u002Fh2>\u003Cp>Seit .NET Core 2.1 ist \u003Ccode>SocketsHttpHandler\u003C\u002Fcode> der empfohlene Handler. Er bietet mehr Kontrolle über Connection-Pooling, DNS-Refresh und Proxy-Selection.\u003C\u002Fp>\u003Cpre>\u003Ccode>using System.Net;\nusing System.Net.Http;\n\nvar proxy = new WebProxy(&quot;http:\u002F\u002Fgate.proxyhat.com:8080&quot;)\n{\n    Credentials = new NetworkCredential(&quot;user-country-US&quot;, &quot;your-password&quot;)\n};\n\nvar handler = new SocketsHttpHandler\n{\n    Proxy = proxy,\n    UseProxy = true,\n    \n    \u002F\u002F Connection-Pool-Tuning für produktive Systeme\n    PooledConnectionLifetime = TimeSpan.FromMinutes(5),\n    PooledConnectionIdleTimeout = TimeSpan.FromMinutes(2),\n    MaxConnectionsPerServer = 100,\n    \n    \u002F\u002F DNS-Refresh für rotierende Proxys\n    EnableMultipleHttp2Connections = true,\n    AutomaticDecompression = DecompressionMethods.All\n};\n\nvar client = new HttpClient(handler);\n\n\u002F\u002F Per-Request Proxy-Override über HttpRequestMessage\nvar request = new HttpRequestMessage(HttpMethod.Get, &quot;https:\u002F\u002Fapi.ipify.org?format=json&quot;);\n\u002F\u002F Proxy kann auch per request.Properties gesetzt werden (fortgeschritten)\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>Warum PooledConnectionLifetime wichtig ist\u003C\u002Fh3>\u003Cp>Bei rotierenden Residential Proxys ändert sich die IP-Adresse regelmäßig. Wenn Sie eine Connection länger als die Rotationszeit offen halten, verwenden Sie möglicherweise eine veraltete IP. Setzen Sie \u003Ccode>PooledConnectionLifetime\u003C\u002Fcode> auf einen Wert unterhalb der Rotationszeit:\u003C\u002Fp>\u003Cpre>\u003Ccode>\u002F\u002F Bei ProxyHat: typische Rotation alle 5-15 Minuten\nvar handler = new SocketsHttpHandler\n{\n    PooledConnectionLifetime = TimeSpan.FromMinutes(3),\n    PooledConnectionIdleTimeout = TimeSpan.FromMinutes(1)\n};\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>Polly: Retry und Circuit Breaker\u003C\u002Fh2>\u003Cp>Proxy-Requests scheitern häufiger als direkte Requests – Rate Limits, Timeouts, IP-Blöcke. Polly bietet eine elegante Lösung für Retry-Logik und Circuit Breaker.\u003C\u002Fp>\u003Cpre>\u003Ccode>using Polly;\nusing Polly.Retry;\nusing Polly.CircuitBreaker;\n\n\u002F\u002F Retry-Strategie: 3 Versuche mit exponentiellem Backoff\nvar retryStrategy = RetryStrategyBuilder&lt;HttpResponseMessage&gt;.Create()\n    .HandleResult(r =&gt; !r.IsSuccessStatusCode)\n    .Handle&lt;HttpRequestException&gt;()\n    .Handle&lt;TaskCanceledException&gt;() \u002F\u002F Timeouts\n    .WaitAndRetryAsync(\n        retryCount: 3,\n        sleepDurationProvider: retryAttempt =&gt; \n            TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),\n        onRetry: (outcome, delay, retryCount, context) =&gt;\n        {\n            Console.WriteLine($&quot;Retry {retryCount} after {delay.TotalSeconds}s: {outcome.Exception?.Message ?? outcome.Result.StatusCode.ToString()}&quot;);\n        });\n\n\u002F\u002F Circuit Breaker: Nach 5 konsekutiven Fehlern für 30s öffnen\nvar circuitBreaker = new CircuitBreakerStrategyBuilder&lt;HttpResponseMessage&gt;()\n    .HandleResult(r =&gt; !r.IsSuccessStatusCode)\n    .Handle&lt;HttpRequestException&gt;()\n    .Handle&lt;TaskCanceledException&gt;()\n    .AdvancedCircuitBreakerAsync(\n        failureThreshold: 0.5, \u002F\u002F 50% Fehlerquote\n        samplingDuration: TimeSpan.FromSeconds(30),\n        minimumThroughput: 5,\n        durationOfBreak: TimeSpan.FromSeconds(30),\n        onOpened: args =&gt; Console.WriteLine(&quot;Circuit breaker opened&quot;),\n        onClosed: args =&gt; Console.WriteLine(&quot;Circuit breaker closed&quot;))\n    .Build();\n\n\u002F\u002F Kombinierte Strategie\nvar resiliencePipeline = new ResiliencePipelineBuilder&lt;HttpResponseMessage&gt;()\n    .AddStrategy(retryStrategy)\n    .AddStrategy(circuitBreaker)\n    .Build();\n\n\u002F\u002F Verwendung\nvar handler = new SocketsHttpHandler\n{\n    Proxy = new WebProxy(&quot;http:\u002F\u002Fgate.proxyhat.com:8080&quot;)\n    {\n        Credentials = new NetworkCredential(&quot;user-country-US&quot;, &quot;your-password&quot;)\n    },\n    UseProxy = true\n};\n\nvar client = new HttpClient(handler);\n\nvar response = await resiliencePipeline.ExecuteAsync(\n    async ct =&gt; await client.GetAsync(&quot;https:\u002F\u002Fhttpbin.org\u002Fstatus\u002F500&quot;, ct),\n    CancellationToken.None);\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>Parallel.ForEachAsync: Concurrent Scraping\u003C\u002Fh2>\u003Cp>Für produktives Web-Scraping müssen Sie mehrere URLs parallel abrufen. \u003Ccode>Parallel.ForEachAsync\u003C\u002Fcode> in .NET 8 bietet eine saubere, effiziente Lösung mit integriertem Throttling.\u003C\u002Fp>\u003Cpre>\u003Ccode>using System.Net;\nusing System.Net.Http;\n\nvar urls = new[]\n{\n    &quot;https:\u002F\u002Fhttpbin.org\u002Fip&quot;,\n    &quot;https:\u002F\u002Fhttpbin.org\u002Fheaders&quot;,\n    &quot;https:\u002F\u002Fhttpbin.org\u002Fuser-agent&quot;,\n    &quot;https:\u002F\u002Fapi.ipify.org?format=json&quot;,\n    &quot;https:\u002F\u002Fifconfig.me\u002Fip&quot;\n};\n\n\u002F\u002F Shared HttpClient (thread-safe)\nvar proxy = new WebProxy(&quot;http:\u002F\u002Fgate.proxyhat.com:8080&quot;)\n{\n    Credentials = new NetworkCredential(&quot;user-country-US&quot;, &quot;your-password&quot;)\n};\n\nvar handler = new SocketsHttpHandler\n{\n    Proxy = proxy,\n    UseProxy = true,\n    MaxConnectionsPerServer = 50, \u002F\u002F Concurrent connections\n    PooledConnectionLifetime = TimeSpan.FromMinutes(3)\n};\n\nusing var client = new HttpClient(handler);\n\n\u002F\u002F Ergebnisse sammeln\nvar results = new System.Collections.Concurrent.ConcurrentBag&lt;(string Url, string Content, TimeSpan Duration)&gt;();\nvar stopwatch = System.Diagnostics.Stopwatch.StartNew();\n\n\u002F\u002F Parallel mit MaxDegreeOfParallelism\nawait Parallel.ForEachAsync(urls, new ParallelOptions\n{\n    MaxDegreeOfParallelism = 10 \u002F\u002F Limit concurrent requests\n}, async (url, ct) =&gt;\n{\n    var sw = System.Diagnostics.Stopwatch.StartNew();\n    try\n    {\n        var response = await client.GetAsync(url, ct);\n        var content = await response.Content.ReadAsStringAsync(ct);\n        sw.Stop();\n        \n        results.Add((url, content, sw.Elapsed));\n        Console.WriteLine($&quot;[{sw.ElapsedMilliseconds}ms] {url}: {content[..Math.Min(100, content.Length)]}...&quot;);\n    }\n    catch (Exception ex)\n    {\n        Console.WriteLine($&quot;Error fetching {url}: {ex.Message}&quot;);\n    }\n});\n\nstopwatch.Stop();\nConsole.WriteLine($&quot;\\nTotal: {stopwatch.ElapsedMilliseconds}ms for {urls.Length} URLs&quot;);\nConsole.WriteLine($&quot;Average: {results.Average(r =&gt; r.Duration.TotalMilliseconds):0.00}ms per request&quot;);\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>Rotating Proxy Pool Service mit DI\u003C\u002Fh2>\u003Cp>Für produktive Anwendungen benötigen Sie einen Proxy-Pool-Service, der IPs automatisch rotiert und mit Dependency Injection funktioniert.\u003C\u002Fp>\u003Cpre>\u003Ccode>using Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Hosting;\nusing System.Net;\nusing System.Collections.Concurrent;\n\n\u002F\u002F Proxy-Konfiguration\npublic class ProxyConfig\n{\n    public string GatewayHost { get; set; } = &quot;gate.proxyhat.com&quot;;\n    public int HttpPort { get; set; } = 8080;\n    public int Socks5Port { get; set; } = 1080;\n    public string Username { get; set; } = &quot;user&quot;;\n    public string Password { get; set; } = &quot;password&quot;;\n    public string[] Countries { get; set; } = [&quot;US&quot;, &quot;DE&quot;, &quot;GB&quot;];\n    public int RotationIntervalSeconds { get; set; } = 300; \u002F\u002F 5 Minuten\n}\n\n\u002F\u002F Proxy-Info\npublic record ProxyInfo(string SessionId, string Country, WebProxy Proxy, DateTime CreatedAt);\n\n\u002F\u002F Proxy-Pool Service Interface\npublic interface IProxyPoolService\n{\n    Task&lt;ProxyInfo&gt; GetProxyAsync(string? country = null, CancellationToken ct = default);\n    Task ReleaseProxyAsync(ProxyInfo proxy, CancellationToken ct = default);\n    Task RotateAllAsync(CancellationToken ct = default);\n}\n\n\u002F\u002F Proxy-Pool Implementation\npublic class ProxyPoolService : IProxyPoolService, IDisposable\n{\n    private readonly ProxyConfig _config;\n    private readonly ConcurrentBag&lt;ProxyInfo&gt; _availableProxies = new();\n    private readonly ConcurrentDictionary&lt;string, ProxyInfo&gt; _inUseProxies = new();\n    private readonly Timer _rotationTimer;\n    private readonly Random _random = new();\n\n    public ProxyPoolService(ProxyConfig config)\n    {\n        _config = config;\n        \n        \u002F\u002F Initiale Proxies erstellen\n        InitializeProxies();\n        \n        \u002F\u002F Automatische Rotation\n        _rotationTimer = new Timer(\n            _ =&gt; RotateAllAsync().GetAwaiter().GetResult(),\n            null,\n            TimeSpan.FromSeconds(_config.RotationIntervalSeconds),\n            TimeSpan.FromSeconds(_config.RotationIntervalSeconds));\n    }\n\n    private void InitializeProxies()\n    {\n        foreach (var country in _config.Countries)\n        {\n            for (int i = 0; i &lt; 5; i++) \u002F\u002F 5 Proxies pro Land\n            {\n                var proxy = CreateProxy(country);\n                _availableProxies.Add(proxy);\n            }\n        }\n    }\n\n    private ProxyInfo CreateProxy(string country)\n    {\n        var sessionId = Guid.NewGuid().ToString(&quot;N&quot;)[..8];\n        var username = $&quot;{_config.Username}-country-{country}-sid-{sessionId}&quot;;\n        \n        var proxy = new WebProxy($&quot;http:\u002F\u002F{_config.GatewayHost}:{_config.HttpPort}&quot;)\n        {\n            Credentials = new NetworkCredential(username, _config.Password)\n        };\n        \n        return new ProxyInfo(sessionId, country, proxy, DateTime.UtcNow);\n    }\n\n    public Task&lt;ProxyInfo&gt; GetProxyAsync(string? country = null, CancellationToken ct = default)\n    {\n        ProxyInfo? proxy;\n        \n        if (country != null)\n        {\n            \u002F\u002F Spezifisches Land suchen\n            proxy = _availableProxies.FirstOrDefault(p =&gt; p.Country == country);\n            if (proxy != null)\n            {\n                _availableProxies.TryTake(out _);\n                _inUseProxies[proxy.SessionId] = proxy;\n            }\n        }\n        else\n        {\n            \u002F\u002F Beliebigen Proxy nehmen\n            if (_availableProxies.TryTake(out proxy!))\n            {\n                _inUseProxies[proxy.SessionId] = proxy;\n            }\n        }\n        \n        if (proxy == null)\n        {\n            \u002F\u002F Neuen Proxy erstellen falls Pool leer\n            proxy = CreateProxy(country ?? _config.Countries[_random.Next(_config.Countries.Length)]);\n            _inUseProxies[proxy.SessionId] = proxy;\n        }\n        \n        return Task.FromResult(proxy);\n    }\n\n    public Task ReleaseProxyAsync(ProxyInfo proxy, CancellationToken ct = default)\n    {\n        _inUseProxies.TryRemove(proxy.SessionId, out _);\n        \n        \u002F\u002F Proxy recyceln falls nicht zu alt\n        if ((DateTime.UtcNow - proxy.CreatedAt).TotalMinutes &lt; 10)\n        {\n            _availableProxies.Add(proxy);\n        }\n        \n        return Task.CompletedTask;\n    }\n\n    public Task RotateAllAsync(CancellationToken ct = default)\n    {\n        Console.WriteLine($&quot;[{DateTime.UtcNow:HH:mm:ss}] Rotating proxy pool...&quot;);\n        \n        \u002F\u002F Alle in Verwendung behalten, verfügbare rotieren\n        var oldProxies = _availableProxies.ToArray();\n        _availableProxies.Clear();\n        \n        foreach (var country in _config.Countries)\n        {\n            for (int i = 0; i &lt; oldProxies.Count(p =&gt; p.Country == country); i++)\n            {\n                _availableProxies.Add(CreateProxy(country));\n            }\n        }\n        \n        return Task.CompletedTask;\n    }\n\n    public void Dispose()\n    {\n        _rotationTimer.Dispose();\n    }\n}\n\n\u002F\u002F HttpClient Factory Integration\npublic static class ProxyServiceExtensions\n{\n    public static IServiceCollection AddProxyPool(\n        this IServiceCollection services,\n        Action&lt;ProxyConfig&gt; configure)\n    {\n        var config = new ProxyConfig();\n        configure(config);\n        \n        services.AddSingleton(config);\n        services.AddSingleton&lt;IProxyPoolService, ProxyPoolService&gt;();\n        \n        \u002F\u002F Named HttpClient mit Proxy-Support\n        services.AddHttpClient(&quot;ProxiedClient&quot;)\n            .ConfigurePrimaryHttpMessageHandler(sp =&gt;\n            {\n                var proxyPool = sp.GetRequiredService&lt;IProxyPoolService&gt;();\n                var proxy = proxyPool.GetProxyAsync().GetAwaiter().GetResult();\n                \n                return new SocketsHttpHandler\n                {\n                    Proxy = proxy.Proxy,\n                    UseProxy = true,\n                    PooledConnectionLifetime = TimeSpan.FromMinutes(3)\n                };\n            });\n        \n        return services;\n    }\n}\n\n\u002F\u002F Verwendung in Program.cs\nvar builder = Host.CreateApplicationBuilder(args);\nbuilder.Services.AddProxyPool(config =&gt;\n{\n    config.Username = &quot;user&quot;;\n    config.Password = &quot;your-password&quot;;\n    config.Countries = [&quot;US&quot;, &quot;DE&quot;, &quot;GB&quot;, &quot;FR&quot;];\n    config.RotationIntervalSeconds = 300;\n});\n\nvar app = builder.Build();\n\n\u002F\u002F Usage\nvar proxyPool = app.Services.GetRequiredService&lt;IProxyPoolService&gt;();\nvar proxy = await proxyPool.GetProxyAsync(&quot;US&quot;);\nConsole.WriteLine($&quot;Got proxy: Session={proxy.SessionId}, Country={proxy.Country}&quot;);\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>TLS: Zertifikats-Pinning und Custom Root CA\u003C\u002Fh2>\u003Cp>Manche Proxy-Anbieter verwenden TLS-Inspection oder Custom Certificates. Hier ist, wie Sie damit umgehen.\u003C\u002Fp>\u003Cpre>\u003Ccode>using System.Net;\nusing System.Net.Http;\nusing System.Net.Security;\nusing System.Security.Authentication;\nusing System.Security.Cryptography.X509Certificates;\n\n\u002F\u002F Custom Certificate Validation (für Development\u002FTest)\nvar handler = new SocketsHttpHandler\n{\n    Proxy = new WebProxy(&quot;http:\u002F\u002Fgate.proxyhat.com:8080&quot;)\n    {\n        Credentials = new NetworkCredential(&quot;user-country-US&quot;, &quot;your-password&quot;)\n    },\n    UseProxy = true,\n    \n    \u002F\u002F TLS-Konfiguration\n    SslOptions = new SslClientAuthenticationOptions\n    {\n        EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13,\n        \n        \u002F\u002F Custom Certificate Validation\n        RemoteCertificateValidationCallback = (sender, cert, chain, errors) =&gt;\n        {\n            \u002F\u002F Für Production: Proper Certificate Pinning\n            if (errors == SslPolicyErrors.None)\n                return true;\n                \n            \u002F\u002F Custom Root CA akzeptieren (nur für bekannte Proxies!)\n            var expectedThumbprint = &quot;YOUR_PROXY_CA_THUMBPRINT&quot;;\n            if (cert is X509Certificate2 cert2 &amp;&amp; \n                cert2.Thumbprint?.Equals(expectedThumbprint, StringComparison.OrdinalIgnoreCase) == true)\n            {\n                return true;\n            }\n            \n            Console.WriteLine($&quot;Certificate validation failed: {errors}&quot;);\n            return false; \u002F\u002F Strict für Production\n        }\n    },\n    \n    \u002F\u002F Connection-Timeout für TLS-Handshake\n    ConnectTimeout = TimeSpan.FromSeconds(30)\n};\n\nvar client = new HttpClient(handler);\n\n\u002F\u002F Certificate Pinning mit bekanntem Public Key\npublic class CertificatePinner\n{\n    private static readonly HashSet&lt;string&gt; _allowedPublicKeys = new()\n    {\n        &quot;sha256\u002FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=&quot;, \u002F\u002F Durch echten Key ersetzen\n        &quot;sha256\u002FBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=&quot;\n    };\n    \n    public static bool ValidateCertificate(\n        HttpRequestMessage request,\n        X509Certificate2? certificate,\n        X509Chain? chain,\n        SslPolicyErrors errors)\n    {\n        if (certificate == null) return false;\n        \n        \u002F\u002F Public Key extrahieren\n        var publicKey = certificate.GetPublicKeyString();\n        var thumbprint = certificate.Thumbprint;\n        \n        \u002F\u002F Pinning-Check\n        var pinnedKey = $&quot;sha256\u002F{Convert.ToBase64String(certificate.GetPublicKeyHash())}&quot;;\n        \n        return _allowedPublicKeys.Contains(pinnedKey) || errors == SslPolicyErrors.None;\n    }\n}\n\n\u002F\u002F Mit HttpClient verwenden\nvar secureHandler = new SocketsHttpHandler\n{\n    Proxy = new WebProxy(&quot;http:\u002F\u002Fgate.proxyhat.com:8080&quot;)\n    {\n        Credentials = new NetworkCredential(&quot;user-country-US&quot;, &quot;your-password&quot;)\n    },\n    UseProxy = true,\n    SslOptions = new SslClientAuthenticationOptions\n    {\n        RemoteCertificateValidationCallback = CertificatePinner.ValidateCertificate\n    }\n};\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>Produktions-Tipps und Best Practices\u003C\u002Fh2>\u003Ch3>1. HttpClient-Lebenszyklus\u003C\u002Fh3>\u003Cul>\u003Cli>\u003Cstrong>Singleton Pattern:\u003C\u002Fstrong> Verwenden Sie \u003Ccode>IHttpClientFactory\u003C\u002Fcode> oder einen Singleton-\u003Ccode>HttpClient\u003C\u002Fcode>. Pro-Request-Instanziierung führt zu Socket-Exhaustion.\u003C\u002Fli>\u003Cli>\u003Cstrong>PooledConnectionLifetime:\u003C\u002Fstrong> Setzen Sie dies auf 3-5 Minuten bei rotierenden Proxys.\u003C\u002Fli>\u003Cli>Timeouts: Setzen Sie angemessene Timeouts (30-60 Sekunden für Proxys).\u003C\u002Fli>\u003C\u002Ful>\u003Ch3>2. Proxy-Rotation\u003C\u002Fh3>\u003Cul>\u003Cli>Session-basiert: Verwenden Sie Session-IDs für Sticky Sessions (gleiche IP für mehrere Requests).\u003C\u002Fli>\u003Cli>Rotation: Rotieren Sie IPs regelmäßig, aber nicht zu häufig (Rate Limits).\u003C\u002Fli>\u003Cli>Geo-Targeting: Nutzen Sie Land\u002FStadt-Targeting für lokale Inhalte.\u003C\u002Fli>\u003C\u002Ful>\u003Ch3>3. Error Handling\u003C\u002Fh3>\u003Cul>\u003Cli>Retry-Logic: Verwenden Sie Polly für automatische Retries mit Backoff.\u003C\u002Fli>\u003Cli>Circuit Breaker: Schützen Sie Ihre Anwendung vor kaskadierenden Fehlern.\u003C\u002Fli>\u003Cli>Logging: Loggen Sie Proxy-IP, Response-Status und Latenz für Debugging.\u003C\u002Fli>\u003C\u002Ful>\u003Ch2>Proxy-Typen im Vergleich\u003C\u002Fh2>\u003Ctable>\u003Cthead>\u003Ctr>\u003Cth>Proxy-Typ\u003C\u002Fth>\u003Cth>Geschwindigkeit\u003C\u002Fth>\u003Cth>Erkennungsrisiko\u003C\u002Fth>\u003Cth>Use Case\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>Datacenter\u003C\u002Ftd>\u003Ctd>Sehr schnell\u003C\u002Ftd>\u003Ctd>Hoch\u003C\u002Ftd>\u003Ctd>High-Volume Scraping, nicht-kritische Targets\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Residential\u003C\u002Ftd>\u003Ctd>Mittel\u003C\u002Ftd>\u003Ctd>Niedrig\u003C\u002Ftd>\u003Ctd>SERP-Scraping, E-Commerce, Social Media\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Mobile\u003C\u002Ftd>\u003Ctd>Variabel\u003C\u002Ftd>\u003Ctd>Sehr niedrig\u003C\u002Ftd>\u003Ctd>Mobile-spezifische Inhalte, Social Media\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003Cp>Für C# residential proxies bietet ProxyHat eine zuverlässige Lösung mit hoher Verfügbarkeit und Geo-Targeting-Optionen.\u003C\u002Fp>\u003Ch2>Weiterführende Ressourcen\u003C\u002Fh2>\u003Cp>Weitere Informationen zu Proxy-Konfigurationen und Use Cases finden Sie in unserer umfassenden Proxy-Anleitung. Für spezifische Anwendungen lesen Sie unseren Guide zu \u003Ca href=\"\u002Fde\u002Fuse-cases\u002Fweb-scraping\">Web-Scraping mit Proxys\u003C\u002Fa>.\u003C\u002Fp>\u003Cp>Die aktuellen ProxyHat-Tarife und verfügbaren Standorte finden Sie auf unserer \u003Ca href=\"\u002Fde\u002Fpricing\">Preisseite\u003C\u002Fa> und der \u003Ca href=\"\u002Fde\u002Flocations\">Standortübersicht\u003C\u002Fa>.\u003C\u002Fp>","C# HTTP Proxy mit .NET 8: HttpClient, SocketsHttpHandler & Polly | Pro","Vollständiger Guide für C# HTTP Proxy mit .NET 8+: HttpClientHandler, SocketsHttpHandler, Polly Retry, Parallel.ForEachAsync und rotierende Proxy-Pools mit DI.","\u002Fde\u002Fblog\u002Fcsharp-http-proxy-guide-2024",null,"C# HTTP Proxy mit .NET 8: Der ultimative Guide","Lernen Sie HTTP-Proxys in C# zu konfigurieren: HttpClient, SocketsHttpHandler, Polly und rotierende Proxy-Pools.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fai\u002F64.jpg",[19,22,25,28,31],{"question":20,"answer":21},"Wie konfiguriere ich einen HTTP Proxy in C# HttpClient?","Verwenden Sie HttpClientHandler oder SocketsHttpHandler mit einem WebProxy-Objekt. Setzen Sie Proxy-Credentials über NetworkCredential und konfigurieren Sie BypassList für lokale Adressen. Bei ProxyHat gehen Credentials in den Username: 'user-country-US:password@gate.proxyhat.com:8080'.",{"question":23,"answer":24},"Was ist der Unterschied zwischen HttpClientHandler und SocketsHttpHandler?","SocketsHttpHandler ist seit .NET Core 2.1 der empfohlene Handler mit besserer Performance und mehr Kontrolle über Connection-Pooling, DNS-Refresh und TLS. HttpClientHandler ist eine Abstraktion, die intern auf SocketsHttpHandler delegiert, aber weniger Konfigurationsoptionen bietet.",{"question":26,"answer":27},"Wie implementiere ich Proxy-Rotation in C#?","Bei ProxyHat rotieren Sie Proxys über Session-IDs im Username: 'user-country-US-sid-abc123'. Für neue IPs verwenden Sie neue Session-IDs. Alternativ implementieren Sie einen Proxy-Pool-Service mit Dependency Injection, der automatisch rotiert.",{"question":29,"answer":30},"Warum sollte ich PooledConnectionLifetime bei Proxys setzen?","Bei rotierenden Residential Proxys ändert sich die IP-Adresse regelmäßig. Wenn Sie Connections länger als die Rotationszeit offen halten, verwenden Sie veraltete IPs. Setzen Sie PooledConnectionLifetime auf 3-5 Minuten, um frische IPs zu garantieren.",{"question":32,"answer":33},"Wie verwende ich Polly mit HttpClient und Proxys?","Erstellen Sie eine ResiliencePipeline mit Retry- und CircuitBreaker-Strategien. Wickeln Sie Ihre HttpClient-Aufrufe mit pipeline.ExecuteAsync(). Polly fängt HttpRequestException, Timeouts und HTTP-Status-Fehler und retryed automatisch mit exponentiellem Backoff.",[35,36,37,38,39],"Verwenden Sie HttpClient als Singleton oder via IHttpClientFactory, um Socket-Exhaustion zu vermeiden.","Nutzen Sie SocketsHttpHandler statt HttpClientHandler für mehr Kontrolle über Connection-Pooling und DNS-Refresh.","Setzen Sie PooledConnectionLifetime unter die Proxy-Rotationszeit, um veraltete IPs zu vermeiden.","Integrieren Sie Polly für Retry-Logik und Circuit Breaker, da Proxy-Requests häufiger scheitern.","Verwenden Sie Parallel.ForEachAsync mit MaxDegreeOfParallelism für effizientes paralleles Scraping.",false,"2026-04-23T04:55:27+00:00","2026-10-03T23:55:51+00:00",14,{"name":45,"slug":46,"bio":47,"avatar_url":14,"website_url":14,"social_links":14},"ProxyHat Team","proxyhat-team","The ProxyHat editorial team covers proxies, web scraping, and data extraction.",[49],{"id":50,"slug":51,"name":52,"description":14,"meta_title":53,"meta_description":54,"parent_id":14},4,"entwickler-anleitungen","Entwickler-Anleitungen","Entwickler-Anleitungen | ProxyHat Blog","Code-Tutorials und SDK-Anleitungen zur Proxy-Integration in Ihre Anwendungen.",[],{"it":57,"en":58,"ja":59,"zh":60,"x-default":58},"\u002Fit\u002Fblog\u002Fcsharp-http-proxy-guida-net-8","\u002Fblog\u002Fcsharp-dotnet-httpclient-proxy-guide","\u002Fja\u002Fblog\u002Fcsharp-http-proxy-dotnet-guide","\u002Fcn\u002Fblog\u002Fcsharp-http-proxy-dotnet-guide",{"it":57,"ko":62,"fr":63,"ru":64,"pt":65,"en":58,"pl":66,"es":67,"ja":59,"de":13,"tr":68,"zh":60},"\u002Fko\u002Fblog\u002Fcsharp-http-proxy-guide-dotnet-8","\u002Ffr\u002Fblog\u002Fcsharp-http-proxy-guide-dotnet-8","\u002Fru\u002Fblog\u002Fcsharp-http-proxy-httpclient-net-8","\u002Fpt\u002Fblog\u002Fcsharp-http-proxy-guia-completo","\u002Fpl\u002Fblog\u002Fcsharp-http-proxy-net-8-przewodnik","\u002Fes\u002Fblog\u002Fguia-http-proxy-csharp-dotnet","\u002Ftr\u002Fblog\u002Fcsharp-httpclient-proxy-rehberi",163,[71,104,131,148],{"id":72,"slug":73,"title":74,"excerpt":75,"featured_image_url":76,"featured_image_alt":77,"card_image_url":78,"og_image_url":79,"published_at":80,"updated_at":81,"content_updated_at":82,"reading_time_minutes":43,"is_featured":40,"indexable":4,"views":83,"author":84,"categories":85,"tags":87},210,"proxy-einrichtung-fuer-ki-agenten","Proxy für KI-Agenten einrichten: browser-use, Crawl4AI und MCP","Agenten auf Cloud-VMs treten mit Datacenter-IPs ins Netz. Hier finden Sie aktuelle, funktionierende Proxy-Konfigurationen für browser-use, Crawl4AI und einen MCP-Server, eine Entscheidungstabelle für Sticky vs. Rotation und die Kostenfallen, die Sie vermeiden sollten.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Fproxy-einrichtung-fuer-ki-agenten-master.webp","Proxy Setup for AI Agents: browser-use, Crawl4AI and an MCP Server","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Fproxy-einrichtung-fuer-ki-agenten-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Fproxy-einrichtung-fuer-ki-agenten-og.webp","2026-10-24T09:00:00+00:00","2026-10-24T09:00:20+00:00","2026-10-03T09:41:41+00:00",39,{"name":45,"slug":46,"bio":47,"avatar_url":14,"website_url":14,"social_links":14},[86],{"id":50,"slug":51,"name":52,"description":14,"meta_title":53,"meta_description":54,"parent_id":14},[88,92,96,100],{"id":89,"slug":90,"name":91},1,"web-scraping","Web Scraping",{"id":93,"slug":94,"name":95},2,"residential-proxies","Residential Proxies",{"id":97,"slug":98,"name":99},9,"python","Python",{"id":101,"slug":102,"name":103},22,"playwright","Playwright",{"id":105,"slug":106,"title":107,"excerpt":108,"featured_image_url":109,"featured_image_alt":110,"card_image_url":111,"og_image_url":112,"published_at":113,"updated_at":114,"content_updated_at":82,"reading_time_minutes":43,"is_featured":40,"indexable":4,"views":115,"author":116,"categories":117,"tags":119},206,"camoufox-residential-proxies-python-anleitung","Camoufox mit Residential Proxies: Python-Anleitung mit Code","So betreiben Sie Camoufox, den in C++ gepatchten Firefox, hinter Residential Proxies: aktuelle Python-API, warum geoip eine Sticky Session braucht, eine Checkliste zur Fingerprint-Kohärenz und wann Patchright oder nodriver besser passt.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Fcamoufox-residential-proxies-python-anleitung-master.webp","Camoufox with Residential Proxies: A Code-First Python Guide","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Fcamoufox-residential-proxies-python-anleitung-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Fcamoufox-residential-proxies-python-anleitung-og.webp","2026-10-13T09:00:00+00:00","2026-10-13T09:00:22+00:00",48,{"name":45,"slug":46,"bio":47,"avatar_url":14,"website_url":14,"social_links":14},[118],{"id":50,"slug":51,"name":52,"description":14,"meta_title":53,"meta_description":54,"parent_id":14},[120,121,122,126,127],{"id":89,"slug":90,"name":91},{"id":93,"slug":94,"name":95},{"id":123,"slug":124,"name":125},6,"anti-erkennung","Anti-Erkennung",{"id":97,"slug":98,"name":99},{"id":128,"slug":129,"name":130},21,"headless-browser","Headless Browser",{"id":132,"slug":133,"title":134,"excerpt":135,"featured_image_url":136,"featured_image_alt":137,"card_image_url":138,"og_image_url":139,"published_at":140,"updated_at":140,"content_updated_at":141,"reading_time_minutes":142,"is_featured":40,"indexable":40,"views":143,"author":144,"categories":145,"tags":147},176,"got-scraping-nodejs-proxy-guide","got-scraping in Node.js: Residential Proxies & Header Generator Praxisleitfaden","Ein entwicklerorientierter Leitfaden zu got-scraping in Node.js mit Residential Proxies: Header-Generierung, Proxy-Rotation, Retry-Hooks und Produktionsmuster für skalierendes Scraping.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Fgot-scraping-nodejs-proxy-guide-master.webp","got-scraping in Node.js: A Developer's Guide with Residential Proxies","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Fgot-scraping-nodejs-proxy-guide-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Fgot-scraping-nodejs-proxy-guide-og.webp","2026-08-04T16:05:06+00:00","2026-11-17T09:21:31+00:00",12,136,{"name":45,"slug":46,"bio":47,"avatar_url":14,"website_url":14,"social_links":14},[146],{"id":50,"slug":51,"name":52,"description":14,"meta_title":53,"meta_description":54,"parent_id":14},[],{"id":149,"slug":150,"title":151,"excerpt":152,"featured_image_url":153,"featured_image_alt":154,"card_image_url":155,"og_image_url":156,"published_at":157,"updated_at":157,"content_updated_at":158,"reading_time_minutes":142,"is_featured":40,"indexable":40,"views":159,"author":160,"categories":161,"tags":163},175,"rotierende-proxies-in-colly","Rotierende Proxies in Colly: Ein Go-Entwickler-Leitfaden für Proxy-Rotation","Praktischer Leitfaden zur Integration rotierender Proxys in Colly mit ProxyHat: RoundRobinProxySwitcher, benutzerdefinierte Proxy-Funktionen, Residential IPs, Retries und Produktionsmuster für verteiltes Scraping.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Frotierende-proxies-in-colly-master.webp","Rotating Proxies in Colly: A Framework-Idiomatic Guide for Go Developers","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Frotierende-proxies-in-colly-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fde\u002Frotierende-proxies-in-colly-og.webp","2026-08-04T10:05:34+00:00","2026-10-03T23:53:00+00:00",86,{"name":45,"slug":46,"bio":47,"avatar_url":14,"website_url":14,"social_links":14},[162],{"id":50,"slug":51,"name":52,"description":14,"meta_title":53,"meta_description":54,"parent_id":14},[],[]]