Bad Request 400: When accessing API with Ionic 3

-1

I'm getting my Bad Request 400 response to my API call in my console:

Myapp.api.tsintheappfolderis:

exportconstMEAT_API='http://localhost:1337'

Andmymaincodeis:

submit(){varlink='http://localhost:1337/user/login';vardata='?email='+JSON.stringify(this.usuario.email)+'&senha='+JSON.stringify(this.usuario.senha);this.http.post(link,data).subscribe(data=>{this.data.response=data._body;if(this.data.response!="[]"){
        var resposta = this.data.response;
        console.log(resposta);

        // tinha que pegar o ID do usuário.... :/
         sessionStorage.setItem("usuarioEmail", this.usuario.email);
         //sessionStorage.setItem("idUsusario", resposta[0].idusuarios);
         sessionStorage.setItem("flagLogado", "sim");

         this.navCtrl.setRoot(WellFitPage, {}, {animate: true, direction: "forward"});
        }else{
          let alert = this.alertCtrl.create({
            title: 'Usuário Não encontrado!',
            subTitle: 'Verifique se digitou seu e-mail e senha corretamente.',
            buttons: ['OK']
          });
          alert.present();
       }
    })
  }

I'm migrating from Ionic 1 to 3 a lot has changed. What can it be? My API was developed using SailsJS.

In my Postman, it seems right, see:

    
asked by anonymous 19.06.2018 / 20:06

1 answer

0

Try this:

const link = 'http://localhost:1337/user/login';
const options =
   { 
       params: new HttpParams()
                  .set('email', this.usuario.email)
                  .set('senha', this.usuario.senha)
    };


    this.http.post(link, options )

A tip usually returns the observable of your service and subscribes to the component.

    
20.06.2018 / 10:08