Native HTTP Post Request Never Executes, No Response Returned


#1

I’m using Native HTTP 4.3.2 with Ionic 3.7.1 to POST data to a server, however the request never seems to get executed. It never gets back a HTTPResponse or even an error.

let url = "https://myserver.com";
let params = { name: 'Me' };
let headers = { 'Accept': 'application/json;charset=UTF-8' };
this.http.post(url, params, headers)
	.then((response:HTTPResponse) => {
		console.log(`Response ${response.data}`);
	})
	.catch((error:any) => {
		console.error(`Error ${error}`);
	});

Doing a GET request works fine, returns back a HTTPResponse, just POST that doesn’t seem to work. Did something break in a recent update?


#2

I posted this issue on cordova-plugin-advanced-http repo in case it’s related to the plugin.


#3

Weird, if I create a brand new Ionic project and add the HTTP plugin, then I am able to both GET and POST just fine.

However when trying to use the HTTP plugin into my existing Ionic project, it never gets back a response from the POST.

I made sure the package.json were using the same Ionic dependencies, although my existing project is using a lot other plugins, perhaps some of them are interfering?


#4

This has been resolved by upgrading to 1.8.1 of the plugin and setting setDataSerializer, explained in https://github.com/silkimen/cordova-plugin-advanced-http/issues/41.


#5

this.http.setDataSerializer(‘json’);

Add this, please