Http.get() working but not working in build(Release/Debug) in Ionic 4

前端 未结 3 901
夕颜
夕颜 2020-11-30 14:52

I am trying get data from a simple api, it works fine in ionic serve(browser) , But when i build the app http call does not work. my Code is



        
3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 15:21

    I think you can use Native HTTP plugin for the device use cases:

    ionic cordova plugin add cordova-plugin-advanced-http
    npm install @ionic-native/http
    

    usage from the doc:

    import { HTTP } from '@ionic-native/http/ngx';
    
    constructor(private http: HTTP) {}
    
    ...
    
    this.http.get('http://ionic.io', {}, {})
      .then(data => {
    
        console.log(data.status);
        console.log(data.data); // data received by server
        console.log(data.headers);
    
      })
      .catch(error => {
    
        console.log(error.status);
        console.log(error.error); // error message as string
        console.log(error.headers);
    
      });
    

提交回复
热议问题