在Ionic 4应用中进行的API调用无法在Android设备上运行 [英] API calls made in Ionic 4 app not working on Android device

查看:93
本文介绍了在Ionic 4应用中进行的API调用无法在Android设备上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用ionic lab命令在笔记本电脑上运行离子应用程序.

I am able to run my ionic app on my laptop by using the ionic lab command.

该应用会调用IMDB api,显示从中检索到的数据.

The app makes calls to the IMDB api, & displays data retrieved from it.

现在,我正在尝试在Android设备上运行该应用程序. 通过使用以下命令:ionic cordova run android --device.

Now, I am trying to run the app on an android device. by using the following command: ionic cordova run android --device.

该应用程序出现在我的手机上,但是当我搜索IMDB数据时,未显示任何结果.

The app appears on my phone, but when I search for IMDB data, no results are appearing.

以下是我用来调用API的服务:

Below is the service I am using to make calls to the API:

export class MovieService {

  url = 'http://www.omdbapi.com/';
  apiKey = 'myKey';

  constructor(private http: HttpClient) { }

  searchData(title: string, type: SearchType): Observable<any> {
    return this.http.get(`${this.url}?s=${encodeURI(title)}&type=${type}&apikey=${this.apiKey}`)
      .pipe(
        map(results => {
          console.log('RAW', results);
          return results['Search'];
        })
      );
  }

  getDetails(id): Observable<any> {
    return this.http.get(`${this.url}?i=${id}&plot=full&apikey=${this.apiKey}`);
  }
}

有人可以告诉我为什么该应用程序可以在我的笔记本电脑上运行,但是当我尝试在手机上使用该应用程序时,该应用程序无法正常工作吗?

Can someone please tell me why the app is working on my laptop, but when I try to use it on my phone it isn't working as expected?

推荐答案

可能的原因之一是您使用的是http而不是https.

Probably one reason is that you are using http not https.

Android在最近的安全更新中限制了对非安全源的访问.

Android restricted access to non-secure feeds in a recent security update.

尝试:

url = 'https://www.omdbapi.com/';

这篇关于在Ionic 4应用中进行的API调用无法在Android设备上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆