I am trying to consume post method of web/api which takes string as parameter, but getting 405 Error : Api Controller Name: Getdata Action Method Name : postdata
please help to identify error.
public bool postdata(string fn)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:59968/api/Getdata");
var task = client.PostAsJsonAsync("Getdata", fn);
task.Wait();
var res = task.Result;
if(res.IsSuccessStatusCode)
{
return true;
}
}
return false;
}
[HttpPost]
public IHttpActionResult postdata(string p)
{
using (var context = new MediaEntities())
{
mediatable m = new mediatable()
{
media_path = p,
is_active = true
};
context.mediatable.Add(m);
context.SaveChanges();
return Ok();
}
}