Http client post request works in Android but not iOS


#1

I am trying to make a post request to a specific URL. On android the following code works fine:

private URL = "http://google.com";
makePost() {
    console.log("Attempting to make post request.");

    const header = new HttpHeaders().set("Content-Type", "text/html");


     /*this.http.get(this.URL).map(response => response).subscribe(res => {
        var message = (<any>res);
        console.log(JSON.stringify(message.text));
     });*/

    this.http.post(this.URL,"Post Data from Nativescript",
      { headers: header })
    .map(response => response)
    .do(data => {
      console.log("Data:" + data);
    })
    .catch(this.handleErrors)
    .subscribe(res => {
        var message = (<any>res);
        console.log(JSON.stringify(message));
    });
  }

However when I try to run this on iOS i get the following error:

file:///app/page1/services/http.service.js:39:20: {"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":null,"ok":false,"name":"HttpErrorResponse","message":"Http failure response for (unknown url): 0 Unknown Error","error":{"line":994,"column":38,"sourceURL":"file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js","originalStack":"ZoneAwareError@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:994:38\nfile:///app/tns_modules/tns-core-modules/http/http-request/http-request.js:87:37\nUIApplicationMain@[native code]\nstart@file:///app/tns_modules/tns-core-modules/application/application.js:258:26\nbootstrapApp@file:///app/tns_modules/nativescript-angular/platform-common.js:86:28\nbootstrapModule@file:///app/tns_modules/nativescript-angular/platform-common.js:72:26\nanonymous@file:///app/main.js:10:57\nevaluate@[native code]\nmoduleEvaluation@[native code]\n[native code]\npromiseReactionJob

From what ive read using HttpClient is the proper way to make the request, however i did try with the old Http module but i get the exact same results. Android working perfectly, but iOS produces:

Http failure response for (unknown url)

#2

Have you setup your NSAppTransportSecurity in info.plist?


#3

No I did not! this was indeed the issue. I was going nuts trying to find information on this error. Thank you so much for pointing me in the right direction.

I used the following solution to update my plist file:

Http post is now working in both android and ios. Thank you very much


#4

Sorry if I should not have post it here as am new and have no idea to raise my issue freshly. My iPhone 7 Plus is casuing issues a lot while playing high end games for more than 10-12mins. Everytime after that time period it is crashing without displaying any error notification/popup. Any idea what to do?

With Regards,
Rohan Daga


#5

Why ? just why did you choose this post to ask your question, and why this forum ? Are those games developed with nativescript ? are they using http connexion ? I don’t think so, it seems you got lost on the internet :sweat_smile:
Anyway you should contact the game developers, or Apple if other iOS devices have no problem running them.