In this case the POST is send to node proxy but we log there header and body. But there is no body in the request and the header is not set with āapplication/jsonā.
We tried to do many things with data and header but nothing changed.
Can someone help for this probably simple problem?
I found out the data has as Content-Type header set application/x-www-form-urlencoded; charset=UTF-8 so the passed data is something like that password=b&username=a and not a json.
For what I see we can not send JSON over native http. OMG
Iām testing the scenario on Emulator ionic cordova emulate android and on device ionic cordova run android so it is like production mode.
In browser cordovaHTTP is not working, so we use simple angular http client with a combination of ionic a nodejs proxy, and this is working like a charm.
On our code we check if platform android or ios is enabled and if so, for our http post we use ionic-native/http instead of angularās http, until here very simple, this is my code:
As described per documentation we have to pass not a json to http.post but a object, so we can not do JSON.stringify(data). So if we launch this code on emulator or device at the server we get a body like this
Action=Login&Password=blabla&UserName=bla
and not a json body!
We try to set the Content-Type header as application/json in many many ways but nothing works.
At server side we have always application/x-www-form-urlencoded; charset=UTF-8 as header.
As we can read in some posts and others, sending object as json in body is not support by plugin!
I knew that this question comes , for me also without --prod is a production mode, --prod does only a small bundle and many optimization.
With production mode I intend, If you run ionic emulate android without -lc you run the app in emulator and with WebView and Cordova functionallity. With --lc you rund the app in browser and donāt have ionic-native/http functionallity available.
Iāll try to share a project in a few minutes! Thank you in the meantime
Those plugins handle JSON post see setDataSerializer
urlencoded: send data as url encoded content in body (content type "application/x-www-form-urlencoded")
json: send data as JSON encoded content in body (content type "application/json")
and also other important things, like handle cookies
I installed this via ionic cordova plugin add cordova-plugin-advanced-http and removed before the default cordova-plugin-http. I also removed ionic-native/http and copied the index.ts file into my project for using the new plugin, so my local file is something like that
But at the end in the emulator and on device I got this error:
Native: tried calling HTTP.post, but the HTTP plugin is not installed
Install the HTTP plugin: 'ionic cordova plugin add cordova-plugin-advanced-http'
But I had installed this before, so Iām really not the expert on this things! Some ideas?
I think I would suggest also the ionic team to use this amazing plugin, there are many enhancements and this two plugins are more maintained then the original one.