My code sample seems to be facing an issue - even though I've set the method as post, it is displaying Request Method as OPTIONS and not setting the request payload.
I'm unsure if this is a CORS problem because it works fine with plugins like Postman and Rest Console in Chrome. Both tools show that the requested server has the correct parameters: Request Method is POST, Content-Type is application/json, and the data in $scope.data should be set as the request payload. What could be causing this issue?
angular.module('httpExample', []).controller('FetchController', ['$scope', '$http', '$templateCache',
function($scope, $http, $templateCache) {
$scope.headers= {
'Accept': '*/*',
'Content-Type': 'application/json; charset=UTF-8'
};
$scope.method = 'POST';
$scope.url = 'http://localhost:56652/reqresp.svc/json/post';
$scope.data={"requests":[{"__type":"AuthenticateAndGetProsties:#LabOra.ProsteModul.ReqResp.Requests", "Authentication":{ "__type":"UserAuthentication:#LabOra.ProsteModul.ReqResp","Username":"xxx","Password":"yyyy" }}]};
$scope.fetch = function() {
$scope.code = null;
$scope.response = null;
$http({method: $scope.method, url: $scope.url,data: JSON.stringify($scope.data),headers:$scope.headers, cache: $templateCache}).
success(function(data,status) {
$scope.status = status;
//$scope.data =x2js.xml_str2json(data);
$scope.data =data;
}).
error(function( status) {
$scope.data = "Request failed";
$scope.status = status;
});
};
}]);
})(window.angular);