DEV Community

Jarod Smith
Jarod Smith

Posted on • Originally published at jarodms.com on

Not able to call REST API on Android, but it works with iOS and Web App

During the development of a recent mobile app, I was retrieving data using a rest api. The web app was working fine and displaying the data. When I deployed to the Android device, I was receiving no data and the following error when calling the api:

Error Code: 0

Message: Http Failure response for [rest api url]

0 Unknown Error

I then deployed to my iPhone and everything worked fine. I was pulling the data back fine and displaying the list of items.

Then I remembered that since this app (which is in beta) was accessing the api using http, not https. I know, I know…it’ll move to https eventually. So that meant I needed to add the following to the android platform entry in the config.xml.

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
   <application android:usesCleartextTraffic="true" />
</edit-config>
Enter fullscreen mode Exit fullscreen mode

This tells Android it’s ok to access data over non-secure (cleartext) traffic.

But…that didn’t work either. That’s weird. Why not? I’ve seen it work just fine in the past, so it was odd.

Ugh. So what I decided to do was remove the android platform, then re-add it, and do a new android build.

Whammy! It works now. I still need the edit-config entry, but apparently, there was something wrong/weird with my previous build files.

The post Not able to call REST API on Android, but it works with iOS and Web App appeared first on JarodMS.

Top comments (0)