How can one use HttpClient and set the method dynamically without having to do something like:
public async Task<HttpResponseMessage> DoRequest(string url, HttpContent content, string method)
{
HttpResponseMessage response;
using (var client = new HttpClient())
{
switch (method.ToUpper())
{
case "POST":
response = await client.PostAsync(url, content);
break;
case "GET":
response = await client.GetAsync(url);
break;
default:
response = null;
// Unsupported method exception etc.
break;
}
}
return response;
}
At the moment it looks like you would have to use:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
new HttpClient()per request, or you can exhaust your socket pool at scale. Use a single static instance.