I'm new to development with ionic, and I need to login to an API, where I need to pass the login header and password in the base64 format, and also need to send the device data through the body ... I already tried everything by google and I could not solve ... Can someone help me, please?
private dispositivo = {
"device_id" : "cleiton_device",
"device_os_version" : "5.0",
"device_model" : "ASUS_T00J",
"device_name" : "ZENFONE",
"device_manufacturer" : "ASUS INC",
"device_api_version" : "19",
"device_width": "800",
"device_height": "600",
"push_key":"token_retornado_pelo_firebase_tanto_no_android_quanto_ios"
};
webReturn: any;
constructor(
public http: Http
) {
}
efetuarLogin(matricula:string, senha:string) {
return new Promise((resolve, reject) => {
let headersObj = new Headers();
headersObj.append("Authorization", "Basic " + btoa(matricula + ":" + senha));
headersObj.append('Access-Control-Allow-Origin' , '*');
headersObj.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT');
headersObj.append('Accept','application/json');
headersObj.append('content-type','application/json');
console.log(headersObj);
console.log(this.dispositivo);
let options = new RequestOptions({ headers:headersObj});
this.http.post(this.URL_API + 'login/loginapp', options)
.subscribe(res => {
this.webReturn = res;
console.log('console do res' + this.webReturn);
}, (err) => {
reject(err);
console.log('console do erro' + err);
});
});
}
error 1: OPTIONS API_KEY 405 (Method Not Allowed)
error 2: Failed to load API_KEY Response for preflight has invalid HTTP status code 405.