cordova-plugin-advanced-http: Post Request Never Executes, No Response Returned
I posted this issue on Ionic Forum, but since it’s likely a plugin issue thought I’d post it here as well.
I’m using Ionic Native HTTP plugin 4.3.2 with Ionic Angular 3.7.1 on iOS 11 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.
I tried to POST to different servers to rule out whether it was a server side issue. Did something break in a recent update of the plugin?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (3 by maintainers)
@AlexGoo looks like that did the trick! Setting
Content-Typehelped, although also needed to changeAcceptfromapplication/json;charset=UTF-8to just application/json`.Perhaps the
application/json;charset=UTF-8was causing the issue?No worries @madsongr, I ran into the same problem. If you wanted to access the
errorin thecatch, you’ll also need to convert it to JSON:I believe the resp.data is a string, so needs to be converted to JSON to access the response values.
let json = JSON.parse(resp.data); console.log(json[0].USERNAME);
@silkimen I’ve upgraded to
"@ionic-native/http": "4.3.3"and"cordova-plugin-advanced-http": "1.7.1"but still no luck, POST never gets back a response.Is there anything that could prevent the request from being executed? Checked the server logs and doesn’t look like it received the request.