내 HTML 클라이언트에서 API를 호출하려고합니다. 그것은 내게 내부 서버 오류를 제공하지만 나는 우편 배달부와 그것을 시도하면 작동합니다. 여기 웹 API 내부 서버 오류
는 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
};
}
내 html로 클라이언트가이
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) {
});
처럼 여기 경로 API를 설정
config.Routes.MapHttpRoute(
name: "RPCApi",
routeTemplate: "{controller}/{action}/{id}",
defaults: new
{
id = RouteParameter.Optional
},
constraints: new
{
subdomain = new SubdomainRouteConstraint("api")
}
);
수있는 사람의 도움을 내 코드입니다 저와 왜 html 클라이언트가 아닌 우편 배달부와 협력하고 있는지 설명해주십시오.
어떤 오류가 발생합니까? – Yoav
찾을 수 없습니다. 404. 기본적으로 API 끝점에 도달 할 수 없습니다. – mohsinali1317
은 예외를 발생시키지 않습니다. 결과는 500입니다.이 경우 400 개의 결과를 반환해야합니다. –