Last post Feb 19, 2015 12:51 PM by Zanak
Feb 17, 2015 12:01 PM|Zanak|LINK
I am new on building web api. i am confused on how to pass data from application (Winphone in my case) to database.
How to create IHttpContent object for my PostAsync or PutAsync method ? i have to pass id, playername, highscore in my database.
Feb 19, 2015 05:27 AM|Sherwin Zhao|LINK
From your description, if you want to pass the parameters from your application to WebApi, you could convert the object to JSON, then send this request.
Please refer to the following code:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:61088/api/Northwind/GetOrders");
request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
var model = new GetOrderViewModel();
model.CustomerID = "1";
var json = Newtonsoft.Json.JsonConvert.SerializeObject(model);
var httpResponse = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
var result = streamReader.ReadToEnd();
public IActionResult GetOrders(GetOrderViewModel model)
Hope this can be helpful to you.
Feb 19, 2015 12:51 PM|Zanak|LINK
Thnx Sherwin. Now i am able to push my content.