我一直在尝试使用$ http.get方法调用API,但不调用该API,而是仅返回404错误。
我的$ HTTP
$http({
method: 'POST',
url: '/SalesManagement/SecuredSalesAPI/GetProductLine'
}).then(function(res) {
debugger
console.log(res.data);
}, function(header) {
debugger
console.log("HTTP Head: " + JSON.stringify(header));
});
//My route public class SalesManagementAreaRegistration : AreaRegistration { public override string AreaName { get { return "SalesManagement"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute("SalesManagement_default",
"SalesManagement/{controller}/{action}/{id}", new { action = "Home", id = UrlParameter.Optional }); } }
我的API:
public class SecuredSalesAPI : Controller
{
public JsonResult GetProductLine()
{
var sp = entity.spGetProductPerformance(startDate, end, "HPL");
return Json(sp, JsonRequestBehavior.AllowGet);
}
}
// and the namespace is
// namespace WebApp.Areas.SalesManagement.Controllers
'方法:'POST','| '试图使用$ http.get'调用一个API <=您的代码与您的语句冲突,这是您实际尝试执行的操作吗? – Igor
如果你不是用户的路由网址,那么首先直接从浏览器进行测试,这对于http GET很有效。如果对Fiddler或PostMan使用非GET终点测试。如果你仍然不确定实际的端点是什么,然后安装[NuGet包Microsoft.AspNet.WebApi.HelpPage](https://www.nuget.org/packages/Microsoft.AspNet.WebApi.HelpPage/),这将在网站上创建一个帮助区域,其中列出了所有可用的Web API端点,包括参数,类型和网址。 – Igor