-
Notifications
You must be signed in to change notification settings - Fork 759
/
Copy pathHttpUnitTests.xaml.cs
55 lines (50 loc) · 1.12 KB
/
HttpUnitTests.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Net.Http;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Uno.UI.Samples.Controls;
namespace SamplesApp.Samples.UnitTests
{
[Sample("WebAssembly", Name = "Wasm Http Handler")]
public sealed partial class HttpUnitTests : Page
{
public HttpUnitTests()
{
this.InitializeComponent();
}
private async void Go(object sender, RoutedEventArgs e)
{
#if __WASM__
var handler = new Uno.UI.Wasm.WasmHttpHandler();
#else
var handler = new HttpClientHandler();
#endif
try
{
using (handler)
using (var client = new HttpClient(handler))
{
Log("Creating a request message");
var request = new HttpRequestMessage(HttpMethod.Get, new Uri(address.Text));
Log("Sending request message");
var response = await client.SendAsync(request);
Log("Reading from response");
var s = await response.Content.ReadAsStringAsync();
result.Text = s;
}
}
catch (Exception ex)
{
while (ex != null)
{
Log($"Exception: {ex}\n\n");
ex = ex.InnerException;
}
}
}
private void Log(string s)
{
log.Text += $"{s}\n";
}
}
}