I'm really struggling with making a basic post request in a url to support a tutorial on web api.
I want to do something like this in browser: http://localhost:59445/api/group/post/?newvalue=test and get the post to register. However I don't seem to be able to form the request correctly. What is the correct way to do this?
The error I receive is:
{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.String Get(Int32)' in 'twin_groupapi.Controllers.GroupController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}
my model:
public class Group
{
public Int32 GroupID { get; set; }
public Int32 SchoolID { get; set; }
public string GroupName { get; set; }
}
routing:
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
controller:
//[Route("api/Group/Post")]
[HttpPost]
public void Post([FromUri] string NewValue)
{
string newstring = NewValue;
}
httpget
? – Sateesh Pagolu// GET: api/Group [Route("api/Group/Get")] [HttpGet] public Array Get()
– oooo ooo