Skip to content

Commit 04fb4b8

Browse files
authored
Migrate to HTTP client (#300)
***NO_CI***
1 parent 40e6142 commit 04fb4b8

File tree

3 files changed

+605
-6
lines changed

3 files changed

+605
-6
lines changed

source/TestAdapter/NanoCLRHelper.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.ComponentModel;
66
using System.Net;
7+
using System.Net.Http;
78
using System.Text.RegularExpressions;
89
using System.Threading;
910
using CliWrap;
@@ -55,23 +56,23 @@ public static bool InstallNanoClr(LogMessenger logger)
5556
string responseContent = null;
5657

5758
// check latest version
58-
using (System.Net.WebClient client = new WebClient())
59+
using (HttpClient client = new HttpClient())
5960
{
6061
try
6162
{
6263
// Set the user agent string to identify the client.
63-
client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
64+
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
6465

6566
// Set any additional headers, if needed.
66-
client.Headers.Add("Content-Type", "application/json");
67+
client.DefaultRequestHeaders.Add("Content-Type", "application/json");
6768

6869
// Set the URL to request.
6970
string url = "https://api.nuget.org/v3-flatcontainer/nanoclr/index.json";
7071

7172
// Make the HTTP request and retrieve the response.
72-
responseContent = client.DownloadString(url);
73+
responseContent = client.GetStringAsync(url).Result;
7374
}
74-
catch (WebException e)
75+
catch (HttpRequestException e)
7576
{
7677
// Handle any exceptions that occurred during the request.
7778
Console.WriteLine(e.Message);

source/TestAdapter/nanoFramework.TestAdapter.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>net48;net6.0</TargetFrameworks>
@@ -22,6 +22,7 @@
2222
<PrivateAssets>all</PrivateAssets>
2323
</PackageReference>
2424
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
25+
<PackageReference Include="System.Net.Http" Version="4.3.4" />
2526
</ItemGroup>
2627

2728
<Import Project="..\TestFrameworkShared\TestFrameworkShared.projitems" Label="Shared" />

0 commit comments

Comments
 (0)