-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPRequestor.cs
More file actions
37 lines (33 loc) · 1.24 KB
/
HTTPRequestor.cs
File metadata and controls
37 lines (33 loc) · 1.24 KB
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
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace MyAudit
{
public static class HttpRequestor
{
private static readonly HttpClient client = new HttpClient();
public static async Task<string> MakeSimpleGetRequestAuth(string url)
{
string token = Environment.GetEnvironmentVariable("API_TOKEN");
try
{
//Sets securely oupor canvas token to our http header
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
//asynchronously makes a get request to the link we want to
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
//stringfy the response
string responseBody = await response.Content.ReadAsStringAsync();
return responseBody;
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
throw;
}
}
}
}