i have a REST client but when y try to do a request the GET method turns into OPTIONS and Always i have 404 Unauthorized error, i tried the same with Postman and everything worked well, here are the code :
rentingApp.factory("AutoCompleteService", ["$http", function ($http) {
return {
search: function (term) {
return $http({
method: "GET",
url: host_base_url + 'site/suggestCity',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'
},
params: {
"term": term
},
});
}
};
}]);
and i have an HttpInterceptor , here is the code:
rentingApp.factory('myHttpInterceptor', function ($q) {
return {
'request': function (config) {
config.headers["Authorization"] = api_id;
return config || $q.when(config);
},
'requestError': function (rejection) {
return $q.reject(rejection);
},
'response': function (response) {
return response;
},
'responseError': function (rejection) {
return $q.reject(rejection);
}
};
}).config(function ($httpProvider) {
$httpProvider.interceptors.push('myHttpInterceptor');
});
Thank you all