c# - 当 VPN 连接处于事件状态时,从 url 返回错误的 Content-Length

标签 c# proxy httpwebrequest vpn

我试图从支持范围请求的 url 中获取部分 Content-Length。但它返回了完整的 Content-Length ,就像没有远程响应一样。我认为这是因为我的机器上有一个事件的桌面 FortiClient VPN 连接。当我关闭此连接时,它运行良好。我该如何解决这个问题?

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();
输出:
Content-Length: 20971520
Accept-Ranges: bytes

最佳答案

我尝试设置一个空代理并且它有效

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

关于c# - 当 VPN 连接处于事件状态时,从 url 返回错误的 Content-Length,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63326792/

相关文章:

java - 为什么InvocationHandler中的invoke()方法有一个参数Object proxy?

JSON POST 中的 C# HttpWebRequest "Request Header"

c# - HttpWebRequest 在第二次调用时超时

c# - 为什么我应该只在开发环境中使用用户 secret ?

c# - Azure Batch - 资源文件准备任务

python - lxml 有代理支持吗?

php - 将file_get_contents与错误的代理一起使用时,如何处理500个内部服务器错误?

php - vb.net通过php向mysql数据库添加文本

c# - 如何在 .NET 4.0 中请求超时或取消之前为 "sleep"

c# - 如何检查数字字符串是否在运行序列中