I am trying to call an api from my html client. It gives me internal server error but when I try it with postman it works.
Here is my code for the api
[AcceptVerbs("POST")]
public dynamic Add(string post,string title, string user)
{
if (post == null)
throw new Exception("Post content not added");
if (title == null)
throw new Exception("Post title not added");
var u = UserManager.FindByEmailAsync(user);
Blog blog = Blog.Create(u.Result.Account.RowKey, post, title).Save();
return new
{
id = blog.Id
};
}
My html client is like this
var d = {
post: post,
title: title,
user: user
}
$.ajax({
type: 'POST',
url: apiUrl + 'Blog/Add',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: JSON.stringify(d)
}).done(function (data) {
console.log(data);
}).fail(function (error) {
});
and here is my code for route api config
config.Routes.MapHttpRoute(
name: "RPCApi",
routeTemplate: "{controller}/{action}/{id}",
defaults: new
{
id = RouteParameter.Optional
},
constraints: new
{
subdomain = new SubdomainRouteConstraint("api")
}
);
Can anyone help me here and explain me why is it working with postman and not with my html client?