Skip to content

Commit ac14a12

Browse files
committed
[#54] [add] switch to Flurl
1 parent a74b735 commit ac14a12

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cSpell.words": [
33
"cref",
4+
"Flurl",
45
"registrator",
56
"seealso",
67
"typeparam"

src/TestClient/Program.cs

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
using System;
2-
using System.Text;
3-
using RestSharp;
2+
using System.IO;
3+
using Flurl.Http;
44

5-
var client = new RestClient("http://localhost:5000/");
6-
7-
var request = new RestRequest("api/v1/testIn", Method.Post)
8-
{
9-
AlwaysMultipartFormData = true
10-
};
11-
12-
request.AddFile("test file", Encoding.UTF8.GetBytes("Hello World!!!"), "MyFile.txt", "text/plain");
13-
14-
var result = client.ExecuteAsync(request).Result;
15-
16-
if (!result.IsSuccessful)
17-
throw new InvalidOperationException("Error sending file: " + result.Content);
5+
var result = await "http://localhost:5000/api/v1/testIn"
6+
.PostMultipartAsync(mp =>
7+
mp.AddFile("test file", new MemoryStream("Hello World!!!"u8.ToArray()), "MyFile.txt", "text/plain"));
188

199
Console.WriteLine("HTTP status: " + result.StatusCode);
2010
Console.ReadLine();

src/TestClient/TestClient.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="RestSharp" Version="110.2.*" />
8+
<PackageReference Include="Flurl.Http" Version="4.0.*" />
99
</ItemGroup>
1010
</Project>

0 commit comments

Comments
 (0)