1
我不知道我的http post方法是怎麼回事。從我讀的內容來看,我的安全性可能存在問題,但我不確定情況如何或如何解決。任何正確的方向洞察力都會很好。angular-seed POST每個瀏覽器的行爲都不一樣
我想發佈到API並檢索迴應並返回數據。當我在IE中運行POST時,我得到了正確的迴應。
但是,當我在Chrome中嘗試這一點時,我得到了奇怪的結果。我的POST變成了OPTIONS方法。狀態碼爲200 OK,但我的回覆爲空。當我嘗試去的URL的情況下直接我得到這個顯示在瀏覽器中的POST:
{「結果」:假的,「錯誤」:「驗證失敗:會話驗證失敗:指定主機名驗證狀態:無效登錄「}
這裏是test.js(控制器)
var host = '255.255.255.255';
var creds = {'logintype':'1','host':host,'user':'Administrator','password':'1234','controlid':'ABC999'};
//var obj = JSON.stringify(creds);
angular.module('myApp.test', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/test', {
templateUrl: 'test/test.html',
controller: 'TestCtrl',
resolve: {
friends: ['$http', function($http) {
return $http({url: 'http://192.168.2.164/ISAPI/rip.dll/REST/SESSIONS/',method: 'POST', data: creds })
.success(function (data) {
return data;
})
.error(function() {
return 'Error';
});
}]
}
});
}])
.controller('TestCtrl', ['$scope', 'friends',function($scope,response) {
$scope.response = response;
}]);
OPTIONS調用正在發生,因爲Chrome對跨域請求執行了一種稱爲「預檢」的操作。您不應該需要將creds對象串聯起來。只需將它直接傳遞給$ http的數據選項。這可能是問題的一部分,所以我建議先嚐試並更新問題。 – itsananderson
我已刪除STRINGIFY,但仍然收到相同的問題。 –