Help with the IONIC REST API 3 tool

Asked

Viewed 61 times

0

I’m new to developing with Ionic, and need to log in to an API, where I need to pass the login and password header in Base64 format, and also need to send the device data by body... I 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.

  • Initially we think as follows: API_KEY 405 - Method not allowed, this error, it seems, occurs because your API does not accept requests post in this URL. As for sending the data in the body of the request, do: this.http.post(this.URL_API + 'login/loginapp', { matricula: matricula , senha: senha }, options) Because the second angular/Ionic HTTP object is body.

  • Maybe it’s the same problem as the question: CORB/CORS error when requesting google api

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.