Note that there are some explanatory texts on larger screens.

plurals
  1. POSending list of objects to Web API
    primarykey
    data
    text
    <p>I am having trouble sending a list of objects to a webapi controller.</p> <p>This is the controler:</p> <pre><code>[AcceptVerbs("POST")] public string syncFoodData(List&lt;intakeSync&gt; str) { string apikey = Request.Headers.GetValues("api_key").ToArray()[0]; return "data syncronised"; } </code></pre> <p>This is the class:</p> <pre><code>public class intakeSync { public int memberID { get; set; } public Double size { get; set; } public string food { get; set; } public string token { get; set; } public string time { get; set; } public string date { get; set; } public string nocatch { get; set; } public string calories { get; set; } } </code></pre> <p>The value of str is always null.</p> <p>this is the webmethod that sends the httprequest to the webapi</p> <pre><code>public static string syncIntakeData(string token, string[] syncString) { JavaScriptSerializer js = new JavaScriptSerializer(); List&lt;intakeSync&gt; str = new List&lt;intakeSync&gt;(); for (int i = 0; i &lt;= syncString.Length - 1; i++) { str.Add(js.Deserialize&lt;intakeSync&gt;(syncString[i])); } string url = URI + "/api/Food/?str=" +js.Serialize(str); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Headers.Add("api_key", token); Stream requestStream = request.GetRequestStream(); StreamReader read = new StreamReader(request.GetResponse().GetResponseStream()); string dat = read.ReadToEnd(); read.Close(); request.GetResponse().Close(); return dat; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload