Created
July 7, 2018 13:11
-
-
Save wuhuangjia/5664edf57f3fcb4655d26ae3f7a99c93 to your computer and use it in GitHub Desktop.
HttpClient sample
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
//make a collection to pack the parameter to send | |
List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>(); | |
paramList.Add(new KeyValuePair<string, string>("action", "encode")); | |
paramList.Add(new KeyValuePair<string, string>("act", act)); | |
paramList.Add(new KeyValuePair<string, string>("pwd", pwd)); | |
//init a httpClient object | |
//and about the ModernHttpClient, please reference below link | |
//https://github.com/paulcbetts/ModernHttpClient | |
HttpClient _httpClient = new HttpClient(new ModernHttpClient.NativeMessageHandler()); | |
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); | |
//post to API | |
HttpResponseMessage httpResponseMessage = await _httpClient.PostAsync(AppData.JWTUrl, new FormUrlEncodedContent(paramList)); | |
httpResponseMessage.EnsureSuccessStatusCode(); | |
//Get the response from api | |
string ticket = await httpResponseMessage.Content.ReadAsStringAsync(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment