HttpClientFactory üzerinden x-www-form-urlencoded body ile form post etme
Aşağıdaki kod örneğinde olduğu gibi veri post edilir
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | var response = new TokenWrapModel(); var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration.GetValue<string>("Authority")); var data = new[] { new KeyValuePair<string, string>("client_id", _configuration.GetValue<string>("ClientId")), new KeyValuePair<string, string>("client_secret", _configuration.GetValue<string>("ClientSecret")), new KeyValuePair<string, string>("grant_type", _configuration.GetValue<string>("GrantType")), }; var result = await client.PostAsync("/connect/token", new FormUrlEncodedContent(data)); if (result.IsSuccessStatusCode) { //Debug.Write(result.Content.ReadAsStringAsync().Result); response.Model = JsonConvert.DeserializeObject<TokenViewModel>(result.Content.ReadAsStringAsync().Result); response.Status = (int)result.StatusCode; } else { response.Status = (int)result.StatusCode; response.Message = "...!"; } |
Yorumlar
Yorum Gönder