pass both string and list as content to HTTPClient RRS feed

  • Question

  • User261343 posted

    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.

    Friday, October 14, 2016 5:05 AM

All replies

  • User66025 posted

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

    Friday, October 14, 2016 6:35 AM
  • User261343 posted

    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:...


    Friday, October 14, 2016 11:00 AM
  • User66025 posted

    @trishelwood, Try to inspect with fiddler

    Try something like this : http://stackoverflow.com/a/13310888/3891036

    Friday, October 14, 2016 11:46 AM