0

loginservice

export class LoginService {
  public token: any;

  constructor( private http:HttpClient) { }
  login(body) {
  const headers=new HttpHeaders;
  headers.append('content-Type', 'application/json'),
  headers.append('api_key', '7zttgA4kFVsD2V2n0beMpzdLQRiSAKxtVEpyeW9MaEFEND0g')

  return this.http.post('https://bell.s2c.io/api/v1/Login', body,
   { headers: headers }).pipe(res=>{return res})
  }}

login.ts

 export class LoginPage implements OnInit {
  private formlogin : FormGroup;
  userId : any 
  token : any 
  constructor(private formBuilder: FormBuilder,private servicelogin:LoginService,
    public toastController: ToastController,private router : Router)
   { 

    this.formlogin = this.formBuilder.group({
    username: ['', Validators.required],
    password: [''],
  });}

  logForm(){
    //console.log(this.formlogin.value);
    this.servicelogin.login(this.formlogin.value).subscribe(data=>{
       let res: any
       res = data;
       console.log(res);


    //this.router.navigateByUrl('/home')

    })


  }
  ngOnInit() {
  }

}

Problem ** Access to XMLHttpRequest at 'https://bell.s2c.io/api/v1/Login' from origin 'http://localhost:8101' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. **someone can help me?

nourhouda
  • 21
  • 5
  • Try to use this plugin https://ionicframework.com/docs/native/http keep on mind that you will can't use a browser to test the requests, you can use an emulator with live reload. – Marco Chavez Sep 10 '19 at 22:31
  • **Marco Chavez** my code login.ts it is true or false ? – nourhouda Sep 11 '19 at 08:11

1 Answers1

0

This is likely an error with your backend not handling CORS properly. Since you are using Flask I would checkout this question.

You can also install browser plugins to help like this one.

Jeremy
  • 3,620
  • 9
  • 43
  • 75