Skip to content

Commit

Permalink
Merge pull request #43 from hmlendea/fix
Browse files Browse the repository at this point in the history
Fixed more network issues
  • Loading branch information
hmlendea authored Jun 17, 2020
2 parents 6ce0f34 + 973e6e7 commit 582adf5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Program

public static void Main(string[] args)
{
Environment.SetEnvironmentVariable("LD_PRELOAD", "/usr/lib/libcurl.so.3");
Environment.SetEnvironmentVariable("DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER", "0");

IConfiguration config = LoadConfiguration();
Expand Down
7 changes: 6 additions & 1 deletion Service/FileDownloader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Net.Http;
using System.Net.Security;
using System.Threading;
Expand Down Expand Up @@ -80,14 +81,18 @@ async Task<string> SendGetRequest(string url)
HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };


HttpClient client = new HttpClient(handler);
client.Timeout = TimeSpan.FromMilliseconds(3000);

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add("User-Agent", applicationSettings.UserAgent);

HttpResponseMessage response = await client.SendAsync(request, CancellationToken.None);

if (response.StatusCode != HttpStatusCode.OK)
{
throw new HttpRequestException($"Failed request. Status code {response.StatusCode}");
}

return await response.Content.ReadAsStringAsync();
}
Expand Down

0 comments on commit 582adf5

Please sign in to comment.