wasSharp – Diff between revs 10 and 14
?pathlinks?
Rev 10 | Rev 14 | |||
---|---|---|---|---|
Line 16... | Line 16... | |||
16 | { |
16 | { |
|
17 | /////////////////////////////////////////////////////////////////////////// |
17 | /////////////////////////////////////////////////////////////////////////// |
|
18 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
18 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
|
19 | /////////////////////////////////////////////////////////////////////////// |
19 | /////////////////////////////////////////////////////////////////////////// |
|
20 | // <summary>A portable HTTP client.</summar> |
20 | // <summary>A portable HTTP client.</summar> |
|
21 | public class wasHTTPClient |
21 | public class wasHTTPClient : IDisposable |
|
22 | { |
22 | { |
|
23 | private readonly HttpClient HTTPClient; |
23 | private readonly HttpClient HTTPClient; |
|
24 | private readonly string MediaType; |
24 | private readonly string MediaType; |
|
Line 25... | Line 25... | |||
25 | |
25 | |
|
Line 265... | Line 265... | |||
265 | catch (Exception) |
265 | catch (Exception) |
|
266 | { |
266 | { |
|
267 | return null; |
267 | return null; |
|
268 | } |
268 | } |
|
269 | } |
269 | } |
|
- | 270 | |
||
- | 271 | /////////////////////////////////////////////////////////////////////////// |
||
- | 272 | // Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // |
||
- | 273 | /////////////////////////////////////////////////////////////////////////// |
||
- | 274 | /// <summary> |
||
- | 275 | /// Sends a GET request to an URL with set key-value pairs. |
||
- | 276 | /// </summary> |
||
- | 277 | /// <param name="URL">the url to send the message to</param> |
||
- | 278 | public async Task<byte[]> GET(string URL) |
||
- | 279 | { |
||
- | 280 | try |
||
- | 281 | { |
||
- | 282 | using (var response = await HTTPClient.GetAsync(URL)) |
||
- | 283 | { |
||
- | 284 | return response.IsSuccessStatusCode ? await response.Content.ReadAsByteArrayAsync() : null; |
||
- | 285 | } |
||
- | 286 | } |
||
- | 287 | catch (Exception) |
||
- | 288 | { |
||
- | 289 | return null; |
||
- | 290 | } |
||
- | 291 | } |
||
- | 292 | |
||
- | 293 | public void Dispose() |
||
- | 294 | { |
||
- | 295 | if (HTTPClient != null) |
||
- | 296 | HTTPClient.Dispose(); |
||
- | 297 | } |
||
270 | } |
298 | } |
|
271 | } |
299 | } |
|
272 | |
300 | |