public static class HttpClientUtils
{
public static async Task DownloadFileTaskAsync(this HttpClient client, Uri uri, string FileName)
{
using (var s = await client.GetStreamAsync(uri))
{
using (var fs = new FileStream(FileName, FileMode.CreateNew))
{
await s.CopyToAsync(fs);
}
}
}
}
var fileName = pathSave + "\\jobs[" + System.Guid.NewGuid() + "].zip";
var uri = new Uri(url);
await client.DownloadFileTaskAsync(uri, fileName);
countDownloaded++;
Thread.Sleep(100);
private static string GetUrl(string id, string proxy , int port)
{
try
{
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://site.com/" + id);
Request.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.79 Safari/537.36";
Request.Method = "GET";
Request.KeepAlive = true;
Request.Timeout = 10000;
WebProxy myproxy = new WebProxy(proxy, port);
Request.Proxy = myproxy;
Request.AllowWriteStreamBuffering = false;
Request.AllowAutoRedirect = false;
Request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
string _url;
using (HttpWebResponse response = (HttpWebResponse)Request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
using (StreamReader sr = new StreamReader(stream, Encoding.UTF8))
{
_url = sr.ReadToEnd();
}
}
}
Request = null;
if (_url != null)
{
_url = Pars(_url, "url=", "\"", 0);
return _url;
}
else
{
return "error";
}
}
catch (Exception ex)
{
return "error";
}
}
List<Object>
в нём .Request.AllowWriteStreamBuffering = false;
Request.AllowWriteStreamBuffering = false;