Javascript Angularjs$http不在GET请求中调用api

Javascript Angularjs$http不在GET请求中调用api,javascript,angularjs,asp.net-mvc,Javascript,Angularjs,Asp.net Mvc,我一直在尝试使用$http.get方法调用API,但它并没有调用该API,而是返回404错误 我的$http $http({ 方法:“POST”, url:“/SalesManagement/SecuredSalesAPI/GetProductLine” }).然后(功能(res){ 调试器 console.log(res.data); },函数(标题){ 调试器 log(“HTTP头:“+JSON.stringify(头)); }); //我的路线公共类SalesManagementArea

我一直在尝试使用$http.get方法调用API,但它并没有调用该API,而是返回404错误

我的$http

$http({
方法:“POST”,
url:“/SalesManagement/SecuredSalesAPI/GetProductLine”
}).然后(功能(res){
调试器
console.log(res.data);
},函数(标题){
调试器
log(“HTTP头:“+JSON.stringify(头));
});
//我的路线公共类SalesManagementAreaRegistration:AreaRegistration{public override string AreaName{get{return“SalesManagement”;}}}public override void RegisterArea(AreaRegistrationContext){context.MapRoute(“SalesManagement_default”,

“SalesManagement/{controller}/{action}/{id}”,新建{action=“Home”,id=UrlParameter.Optional};}}
您试图获取,但将方法定义为post


$http({
方法:“GET”,
url:“/SalesManagement/SecuredSalesAPI/GetProductLine”
}).然后(功能(res){
调试器
console.log(res.data);
},函数(标题){
调试器
log(“HTTP头:“+JSON.stringify(头));
});

将方法更改为“GET”而不是“POST”

$http({
            method: 'GET',
            url: '/SalesManagement/SecuredSalesAPI/GetProductLine'
        }).then(function (res) {

            console.log(res.data);
        }, function (header) {

            console.log("HTTP Head: " + JSON.stringify(header));
        });
还要将关键字controller添加到控制器类名中。ie;
公共类SecuredSalesApicController:控制器 { }
并像以前一样从客户端调用服务。

API仅通过url传递数据。您必须使用GET方法来获取数据

$http({
    method: 'GET',
    url: '/SalesManagement/SecuredSalesAPI/GetProductLine'
}).then(function(res) {

    debugger
    console.log(res.data);

}, function(header) {

    debugger
    console.log("HTTP Head: " + JSON.stringify(header));

});

method:'POST',
|
尝试使用$http调用API。get
如果您不是用户,请首先直接从浏览器测试路由url,这对http get非常有效。如果与Fiddler或PostMan一起使用非GET端点测试。如果您仍然不确定最终点是什么,然后安装,这将在您的站点中创建一个帮助区域,其中包含一个页面,列出所有可用的web api端点,包括参数、其类型和URL。检查区域内的路由配置,并检查如何定义路由刚刚更新我的AreaRegistration。其他文件中的所有其他API和$http都在工作,但不是这样。您可以尝试使用$http.get('/SalesManagement/SecuredSalesAPI/GetProductLine')。然后(函数(响应){});此外,控制器名称应紧跟在单词controller之后。但是你的控制器名称中没有。不是在url中,而是在classnamepublic类SecuredSalesApicController:Controller中。在类名中添加关键字controller。希望它能解决这个问题。并像以前一样调用api$http({method'GET',url:'/SalesManagement/SecuredSalesAPI/GetProductLine'})。然后(函数(res){Issac Johnson,SecuredSalesAPIController:Controller工作得很好。感谢您为我指明了正确的方向。