Skip to content

Instantly share code, notes, and snippets.

@wuhuangjia
Created July 7, 2018 13:11
Show Gist options
  • Save wuhuangjia/5664edf57f3fcb4655d26ae3f7a99c93 to your computer and use it in GitHub Desktop.
Save wuhuangjia/5664edf57f3fcb4655d26ae3f7a99c93 to your computer and use it in GitHub Desktop.
HttpClient sample
//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