Last active
October 13, 2018 10:56
-
-
Save Mirch/1cedb4d9e37ee4bf5ef50915832f16de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RequestSender | |
{ | |
private static Dictionary<string, HttpClient> _CLIENTS = new Dictionary<string, HttpClient>(); | |
private HttpClient _client; | |
public RequestSender(string baseURI) | |
{ | |
var value = _CLIENTS.GetValueOrDefault(baseURI); | |
if (value == null) | |
{ | |
var newClient = new HttpClient(); | |
newClient.BaseAddress = new Uri(baseURI); | |
_CLIENTS.Add(baseURI, newClient); | |
_client = newClient; | |
} | |
else | |
{ | |
_client = _CLIENTS.GetValueOrDefault(baseURI); | |
} | |
} | |
public async Task<string> Get(string path) | |
{ | |
var response = await _client.GetStringAsync(path); | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment