Web API 调用在设备模式下失败

Web API call failed in Device mode

本文关键字:模式 失败 API 调用 Web      更新时间:2023-09-26

我已经在Cordova(VS2015)中实现了小型移动应用程序。在我的应用程序中,我使用 wep api 获取 asp.net 所有必需的数据。我的移动解决方案在瑞波模拟器中工作正常。但不能在设备模式(Andorid)下工作。我已经发布了我的 Web 服务和本地 IIS 服务器,我使用本地 IP 地址和端口号来访问它。此外,我也在我的 Web api 中启用了跨域调用。

波纹管是我的应用程序.js查找和服务,我已经使用angularJS实现。

var app = angular.module('RandBApp', ['ionic', 'RandBApp.controllers'])

.run(function ($ionicPlatform) { $ionicPlatform.ready(function () { if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); } 如果(窗口。状态栏) { StatusBar.styleDefault(); } });})

.config(function ($compileProvider, $stateProvider, $urlRouterProvider, $httpProvider) {

$compileProvider.aHrefSanitizationWhitelist(/^'s*(https?|ftp|mailto|file|ghttps?|ms-appx|x-wmapp0):/);
$compileProvider.imgSrcSanitizationWhitelist(/^'s*(https?|ftp|file|ms-appx|x-wmapp0):|data:image'//);
$stateProvider
.state('app', {
    url: "/app",
    abstract: true,
    templateUrl: "app/views/menu.html",
    controller: 'RandBAppCtrl'
})
.state('app.products', {
    url: "/products",
    cache: false,
    views: {
        'menuContent': {
            templateUrl: "app/views/products.html",
            controller: 'ProductsCtrl'
        }
    }
})
.state('app.productdetail', {
    url: "/products/:productid",
    views: {
        'menuContent': {
            templateUrl: "app/views/productdetail.html",
            controller: 'ProductDetailCtrl'
        }
    }
})
.state('app.signup', {
    url: "/signup",
    cache: false,
    views: {
        'menuContent': {
            templateUrl: "app/views/signup.html",
            controller: 'SignUpCtrl'
        }
    }
})
  .state('app.reservations', {
      url: "/reservations",
      cache: false,
      views: {
          'menuContent': {
              templateUrl: "app/views/reservations.html",
              controller: 'ReservationsCtrl'
          }
      }
  })
.state('app.reservationdetail', {
    url: "/reservations/:reservationid",
    views: {
        'menuContent': {
            templateUrl: "app/views/reservationdetail.html",
            controller: 'ReservationDetailCtrl'
        }
    }
})
.state('app.orders', {
    url: "/orders",
    cache: false,
    views: {
        'menuContent': {
            templateUrl: "app/views/orders.html",
            controller: 'OrdersCtrl'
        }
    }
})
.state('app.orderdetail', {
    url: "/orders/:orderid",
    views: {
        'menuContent': {
            templateUrl: "app/views/orderdetail.html",
            controller: 'OrderDetailCtrl'
        }
    }
})
    .state('app.loyaltyhistory', {
        url: "/loyaltyhistory",
        cache: false,
        views: {
            'menuContent': {
                templateUrl: "app/views/loyaltyhistory.html",
                controller: 'LoyaltyHistoryCtrl'
            }
        }
    })
.state('app.notifications', {
    url: "/notifications",
    cache: false,
    views: {
        'menuContent': {
            templateUrl: "app/views/notifications.html",
            controller: 'NotificationsCtrl'
        }
    }
});

$urlRouterProvider.otherwise('/app/products');

});

var serviceUrl = 'http://localhost:6787/';

app.constant('ngAuthSettings', { apiServiceBaseUri: serviceUrl, clientId: 'ngAuthApp', loginCredentail: 'loginCredentail'});

这是我的服务

app.factory('loyaltyservice', ['$http', '$q', '$log', 'ngAuthSettings', function ($http, $q, $log, ngAuthSettings) {

var loyaltyFactory = {};
var webAPIbase = ngAuthSettings.apiServiceBaseUri;
var loginCredentailKey = ngAuthSettings.loginCredentail;
var getLoyaltyTransactionDetails = function (userId) {
    var deferred = $q.defer();
    $http({
        method: 'GET',
        url: webAPIbase + "api/Loyalty/GetLoyaltyTransactionDetails",
        params: {
            userId: userId
        }
    }).success(function (response) {
        deferred.resolve(response);
    }).error(function (err, status, header, config) {
        deferred.reject(err);
    });
    return deferred.promise;
};
loyaltyFactory.getLoyaltyTransactionDetails = getLoyaltyTransactionDetails;
return loyaltyFactory;

}]);

任何帮助真的很感激。

对不起,伙计们。我忘了启用防火墙中的端口。启用后,它开始工作。