Search code examples
c#proxyhttpwebrequestvpn

Wrong Content-Length returned from url when VPN connection is active


I tried to get partial Content-Length from a url that supports ranged request. But it returned full Content-Length like there is no ranged response. I think this is because there is an active desktop FortiClient VPN connection on my machine. When I closed this connection it works well. How can I fix this problem?

var url = "http://ipv4.download.thinkbroadband.com/20MB.zip";
var req = (HttpWebRequest)WebRequest.Create(url);
req.UserAgent = "C# Application";
req.AddRange(0, 100);
var resp = (HttpWebResponse)req.GetResponse();
Console.WriteLine("Content-Length: " + resp.ContentLength);
Console.WriteLine("Accept-Ranges: " + resp.Headers["Accept-Ranges"]);
Console.ReadKey();

Output:

Content-Length: 20971520
Accept-Ranges: bytes

Solution

  • I tried setting an empty proxy and it worked

    req.Proxy = new Proxy(); //or
    req.Proxy = null;