how send post request to httpclient in application/x-www-form-urlencoded with different data types

Viewed 39

I want to send 5 string data with one float data which is the amount but form URL encode only wants a string, string key pair

I try to send 5 string data and one float data which is an amount in dictionary <string, dynamic> but form URL encode only allows <string, string> then how do I send different data types to the application/x-www-form-urlencoded client? and also how I get data from the response. it's a payu integration for refund API.

StringContent content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/x-www-form-urlencoded");
                   
                    HttpClient client = new HttpClient();
                   
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                   
                    var PayuResponse = client.PostAsync(url, new FormUrlEncodedContent(data)).Result;
                   
                    var json = PayuResponse.Content.ReadAsStringAsync().Result;
1 Answers

If there are always 6 parameters (5 strings and 1 float) I prefer to make a Model and use Model Binding to get parameters and after that, you can create a dictionary or what so ever you need.

Related