You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Core 2.2 HttpClient/WebClient对比Curl请求部分服务器速度过慢

HttpClient/WebClient in .NET Core 2.2 is drastically slower than curl/lynx for certain servers (2-50x speed difference)

I've been testing HTTP requests on Ubuntu 18.04 (.NET Core 2.2.203) and Windows 10, and noticed that .NET Core's HttpClient/WebClient is significantly slower than curl or lynx when accessing some servers—with speed differences ranging from 2x up to 50x.

Test Setup

  • I used the recommended static HttpClient (also tested the using() disposable pattern, which yielded the same slow results)
  • Timing implementation for .NET code:
    sw.Start(); // Stopwatch timing
    client.GetAsync(url).Result();
    sw.Stop();
    
  • Comparison commands for native tools:
    • Curl: time curl -L "url" > /dev/null
    • Lynx: time lynx "url" > /dev/null

Troubleshooting Attempts

I've tried every fix I could find via search, but none resolved the slowdown except wrapping curl via CurlThin:

  • Disabled proxy in HttpHandler: UseProxy = false, Proxy = null
  • Replaced .Result() with await (proper async/await pattern)
  • Switched to WebClient instead of HttpClient
  • Tried the ModernHttpClient library
  • Only curl wrappers like CurlThin matched the normal speed of native curl/lynx; all other .NET native approaches remained extremely slow.

This issue also reproduces with PowerShell's Invoke-WebRequest on Windows.

Reproduction Code & Scripts

.NET Repro Code

Run with: dotnet run -- https://reddit.com

using System;
using System.Diagnostics;
using System.Net.Http;

namespace Download.Playground
{
    class Program
    {
        static HttpClient client;
        static void Main(string[] args)
        {
            HttpClientHandler hch = new HttpClientHandler();
            hch.Proxy = null;
            hch.UseProxy = false;
            client = new HttpClient(hch);
            Stopwatch sw = new Stopwatch();
            sw.Start();
            var result = client.GetAsync(args[0]).Result;
            sw.Stop();
            Console.WriteLine($"Spent {sw.ElapsedMilliseconds}ms");
        }
    }
}

Benchmark Script

Run with: ./runbench https://reddit.com

#!/bin/bash
for i in {1..20}
do
    dotnet run -- $1
    time curl -L $1 > /dev/null
done

Has anyone encountered this exact issue? I've exhausted all documented fixes I could find, but nothing gets .NET's native HTTP clients to perform on par with curl/lynx for these servers.


内容的提问来源于stack exchange,提问作者CharlesS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:28:48