I'm trying to make a post request using the ionic native HTTP module in my ionic app. When I run the app using Ionic DevApp, the request works and the app works fine. When I use ionic cordova run android --device
to build and run the app natively on my device, the http request is failing.
I've been trying a bunch of options listed in other stack overflow questions. I've installed cordova-plugin-whitelist
and modified my config.xml to include all different types of access orgin and allow navigations. I also made sure my Android Manifest has:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
I'm at a loss for what else I can try and I figured this is not a CORS issue with the API since the request is working perfectly when I use ionic serve -c
to run it through the Ionic DevApp.
Just for reference, my API request looks like:
var headers = {}
this.http.setDataSerializer('json')
return this.http.post(API_URL, send_data, {headers: headers})
.then(data => {
...
}
In my config.xml
file I've included:
<access origin="*" />
<access origin="*" subdomains="true" />
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="localhost:8080" />
<allow-navigation href="data:*" />
<allow-intent href="http://*/*" />
<allow-intent href="localhost:8080" />
Any guidance would be greatly appreciated, this has been a huge time drain and the frustrating thing is the app is fully functional and succesfully making the http post request from the Ionic DevApp. Thanks.
Have you tried connecting the chrome debugger to see why your post request fails? You can do this by going to chrome://inspect You should be able to see your app there (assuming your phone is connected and in dev mode). Once you see your app, click inspect. This should open a chrome debugger window allowing you to see the network traffic.
Please reply with the result.