public void SendDelete(string url, Dictionary <string, string> queryParameters, IEnumerable <Cookie> cookies = null) { using (var client = CreateHttpClient(CreateCookieContainer(cookies))) { using (var response = client.DeleteAsync(GetFullUrl(url, queryParameters)).Result) { if (!response.IsSuccessStatusCode) { throw HttpClientException.Create(response); } } } }
public async Task <T> SendPostAsync <T>(string url, Dictionary <string, string> queryParameters = null, IEnumerable <Cookie> cookies = null) { using (var client = CreateHttpClient(CreateCookieContainer(cookies))) { using (var response = client.PostAsync(GetFullUrl(url, queryParameters), new StringContent(string.Empty)).Result) { if (!response.IsSuccessStatusCode) { throw HttpClientException.Create(response); } return(await response.Content.ReadAsAsync <T>().ConfigureAwait(false)); } } }
public async Task <CookieCollection> SendEncodedFormPostAsync(string url, Dictionary <string, string> formData) { var cookies = new CookieContainer(); using (var client = CreateHttpClient(cookies)) { using (var response = await client.PostAsync(url, new FormUrlEncodedContent(formData))) { if (!response.IsSuccessStatusCode) { throw HttpClientException.Create(response); } return(cookies.GetCookies(new Uri(url))); } } }
private async Task <string> SendGetStringAsync(string url, Dictionary <string, string> queryParameters = null, IEnumerable <Cookie> cookies = null) { using (var client = CreateHttpClient(CreateCookieContainer(cookies))) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); using (var response = await client.GetAsync(GetFullUrl(url, queryParameters), HttpCompletionOption.ResponseContentRead)) { if (response.StatusCode == HttpStatusCode.NotFound) { return(default(string)); } if (!response.IsSuccessStatusCode) { throw HttpClientException.Create(response); } return(await response.Content.ReadAsStringAsync().ConfigureAwait(false)); } } }