Forum Xamarin.Forms

pass both string and list as content to HTTPClient

Hello All,

I want to call API that has multiple values of strings and multiple lists.

dynamic values = new Dictionary<dynamic, dynamic>(); values.Add("DocId", _DocId); values.Add("UserName", _UserName); values.Add("Address", _Address); values.Add("education", _education); // here, _education and _awards are lists. and _DocId, _UserName and _Address are strings. values.Add("awards",_awards); var content = new FormUrlEncodedContent(values);

I pass Content to httpClient.PostAsync() method with url. Now problem is when I pass list as content it gives error of not supporting datatype. What is wrong in this ?

Any help would be appreciated.

Thank you.



  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited October 2016

    @trishelwood, Try serializing your list to json, and pass the resultant json.

  • trishelwoodtrishelwood USMember ✭✭

    Thanks @YkshLeo for answering. I tried using Json as you suggested.

    But it now throws Internal Server Error in response. it takes content-type as 'text/html'

    Here is my code.

    var httpClient = new HttpClient(); var response = await httpClient.PostAsync(APIURL, new StringContent(newjson, Encoding.UTF8, "application/json")); // newjson is name of my json file.

    In return, it gives

    {StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:...


  • YkshLeoYkshLeo USMember ✭✭✭✭

    @trishelwood, Try to inspect with fiddler

    Try something like this :

Sign In or Register to comment.