Last active
March 1, 2018 18:25
-
-
Save bronumski/0406394ff91f07ddf3da8b68512b7d8e to your computer and use it in GitHub Desktop.
Change request header for individual requests
This file contains hidden or 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 static Task<HttpResponseMessage> GetAsync | |
| (this HttpClient httpClient, string uri, Action<HttpRequestMessage> preAction) | |
| { | |
| var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uri); | |
| preAction(httpRequestMessage); | |
| return httpClient.SendAsync(httpRequestMessage); | |
| } | |
| public static Task<HttpResponseMessage> PostAsJsonAsync<T> | |
| (this HttpClient httpClient, string uri, T value, Action<HttpRequestMessage> preAction) | |
| { | |
| var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, uri) | |
| { | |
| Content = new ObjectContent<T> | |
| (value, new JsonMediaTypeFormatter(), (MediaTypeHeaderValue)null) | |
| }; | |
| preAction(httpRequestMessage); | |
| return httpClient.SendAsync(httpRequestMessage); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment