Skip to content

Instantly share code, notes, and snippets.

@mebjas
Last active September 21, 2016 10:39
Show Gist options
  • Save mebjas/e0d65b0930e2fe81cc02e8b95985ad50 to your computer and use it in GitHub Desktop.
Save mebjas/e0d65b0930e2fe81cc02e8b95985ad50 to your computer and use it in GitHub Desktop.
handelling post with web api
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Net.Http.Headers;
namespace testwebapp.Controllers
{
public class OMSInput {
public string severity = String.Empty;
public string description = String.Empty;
};
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public HttpResponseMessage Post([FromBody]OMSInput value)
{
var resp = new HttpResponseMessage()
{
Content = new StringContent("{\"ack\":\"true\"}")
};
resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
return resp;
}
// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment