Forum Xamarin.Forms

how to pass json object as an value for one of the key in post request?

I have three keys personname,billingdate and nozzolereadings...I am able to work with name and date as it is simple string but nozzolereadings is asking for json object as a value..

My required json request is:
personname name
billingdate 2019-01-01
nozzolereadings [{"opening_reading":"7687","closing_reading":"7691289"},{"opening_reading":"103250","closing_reading":"103348"}]

Anyone suggest please how to send [{"opening_reading":"7687","closing_reading":"7691289"},{"opening_reading":"103250","closing_reading":"103348"}] as value to post request ?This is my code for sending request to API and getting response...

class Bill
public async static Task AddBillData(string name,string date)

          Uri uri = new Uri(urlname);

        var postData = new List<KeyValuePair<string, string>>
                new KeyValuePair<string, string>("personname",name),
                new KeyValuePair<string, string>("billingdate",date),


        HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, uri);
        req.Content = new FormUrlEncodedContent(postData);

        using (HttpClient client = new HttpClient())
            var response = await client.SendAsync(req);

            var content = await response.Content.ReadAsStringAsync();

            statusCheck = JsonConvert.DeserializeObject<StatusView>(content);

        return statusCheck;


Best Answer


  • MonalishaMonalisha Member ✭✭

    Thanks a lot ...
    This is what I exactly want

  • shweta_gopishweta_gopi Member

    Hi, i have to pass two key, value pair in form data to call Webapi . For that what code we need to change . when i use this code ,its giving error of 'Host unknown".Suggest me as soon as possible. i am attaching a screen shot of postman . i have to pass those 2 parameter from c# code.

Sign In or Register to comment.