I am building a hybrid App using ionic for the first time. I have to create a library which will connect all the controllers to the external API. I have authentication error. I have the following code:
angular.module('starter.services', [])
.factory('apiConnect',function(){
var sslurl = 'urltoexternal Api';
var apiConnect = function(){
this.vesion = '3.0';
this.prefix = 'oauth_';
this.key = key;
this.secret = secret;
this.sslurl = '';
}
apiConnect.prototype.callservice = function(call, $http,$resource) {
var endpoint = sslurl + call;
$http({
method: 'POST',
url: sslurl + call,
headers: {
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT',
'Content-Type': 'application/json',
'Accept': 'application/json',
'oauth_nonce': '47901059',
},
data: {
}
}).then(function(resp) {
console.log('Success', resp);
// For JSON responses, resp.data contains the result
}, function(err) {
console.error('ERR', err);
// err.status will contain the status code
})
}
I get the following error
No 'Access-Control-Allow-Origin' header is present on the requested resource. I want to pass the following
- oauth_nonce,oauth_timestamp,oauth_key,oauth_signature in the header.
- I want to call POST method but it always call OPTIONS
- I want to send and receive json How do I pass this values and get the response? What is the correct approach for this kind of rest connection.