About the @ionic-native/http/ngx

I want to make a post request by this library because when i post by @angular/common/http, it is have error that CROS. I dont know why and i try to use @ionic-native/http/ngx. But i have a error that Object(…) is not a function. Please help me. I make a project alone and deadline is comming :frowning:

CORS really really needs to be dealt with on the server. If you don’t control the server, ask whoever does to deal with this.

Could you post an example of how you are implementing the native HTTP package? Here is what my post function looks like.

  post(endpoint: string, body: any, token?: string) {
    const headers = this.createHeaders(token);
    if (this.hasCordova) {
      this.httpNat.setDataSerializer('json');
      return from(this.httpNat.post(this.apiUrl + '/' + endpoint, body, null).then(response => {
          return JSON.parse(response.data);
        }).catch(error => {
          console.log(error.status);
          console.log(error.error);
          console.log(error.headers);
        }));
    } else {
    return this.http.post(this.apiUrl + '/' + endpoint, body, { headers });
    }
  }

i think the reason is how did i send post request. They have a sample by PHP. I test by it. it is ok. But when i coded by ionic. It is CROS

OK then. I’m not going to force you to listen to me.


i follow by this link. Sorry Because i reply late. But my bug is not done :frowning:

First install
npm install --save @angular/common/http

i have created one function called login() with http

code:

import { HttpClient } from ‘@angular/common/http’;

export class LoginPage implements OnInit {

films : any;
constructor(public httpClient: HttpClient) {
}
login(mobile)
{
this.films = this.httpClient.get(“https://yoururl/foldername/myfile.php?mobile=”+mobile);
this.films.subscribe(data => {
console.log(data);
});
}
}