Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have quite a few issues here, but generally you should be posting your data, not using a GET url, to create a post: domain.com/controller/action/some/data/here is a get request. domain.com/controller/action is your post URL, with the data in the post url form params. You would then bind your action to a model, and not to single params like you have done.</p> <p>Here is some code I use in my baseclass to make all API calls, when calling the API from serverside code:</p> <pre><code>public string CreateApiRequest(string url, object model, bool isPost) { try { ASCIIEncoding encoding = new ASCIIEncoding(); string postData = ""; if(model != null) { postData = Strings.SerializeToQueryString(model).TrimEnd(Convert.ToChar("&amp;")); } byte[] data = encoding.GetBytes(postData); var serviceUrl = "http://" + HttpContext.Request.Url.Host + "/api/{0}"; // create the post and get back our data stream var myRequest = (HttpWebRequest)WebRequest.Create(new Uri(string.Format(serviceUrl, url))); if (isPost) { myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.Accept = "application/json"; myRequest.ContentLength = data.Length; Stream newStream = myRequest.GetRequestStream(); // Send the data. newStream.Write(data, 0, data.Length); newStream.Close(); } else { myRequest.Method = "GET"; myRequest.Accept = "application/json"; } // Get response using (HttpWebResponse response = myRequest.GetResponse() as HttpWebResponse) { // Get the response stream var reader = new StreamReader(response.GetResponseStream()); // Read the whole contents and return as a string var myString = reader.ReadToEnd(); return myString; } } catch (Exception ex) { // handle error here, I have my own custom mailer throw; } } </code></pre> <p>and this is how I call it.</p> <pre><code>var model = JsonConvert.DeserializeObject&lt;List&lt;Address&gt;&gt;(CreateApiRequest(url: "Address", model: null, isPost: false)); </code></pre> <p>hope this helps </p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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