Http post request work on android but not Ios


#1

I am trying using http request to my golang server everything works fine with android but not IOS.

below is my service for testing:

import { Injectable } from “@angular/core”;
import { HttpClient, HttpHeaders, HttpResponse } from “@angular/common/http”;

@Injectable()
export class MyHttpPostService {
private serverUrl = “http://10.0.2.2:3001/auth”;

constructor(private http: HttpClient) { }

postData(data: any) {
    let options = this.createRequestOptions();
    return this.http.post(this.serverUrl, { data }, { headers: options });
}

private createRequestOptions() {
    let headers = new HttpHeaders({
        "AuthKey": "my-key",
        "AuthToken": "my-token",
        "Content-Type": "application/json"
    });
    return headers;
}

}

and here is my component:import { Component, OnInit } from “@angular/core”;
import * as app from “tns-core-modules/application/application”;
import { RadSideDrawer } from “nativescript-ui-sidedrawer”;

import { MyHttpPostService } from ‘./home.service’;

@Component({
selector: “Home”,
moduleId: module.id,
templateUrl: “./home.component.html”
})
export class HomeComponent implements OnInit {

public username: string;
public password: string;

public message: string = "";
public token: string;
public userData: {};
constructor(private myPostService: MyHttpPostService) { }
ngOnInit(): void {
    this.username = "TEST";
    this.password = '123456';
}

onDrawerButtonTap(): void {
    const sideDrawer = <RadSideDrawer>app.getRootView();
    sideDrawer.showDrawer();
}
public checkServer() {
    // alert("test");
    this.makePostRequest();

}
private makePostRequest() {
    this.myPostService
        .postData({ username: this.username, password: this.password, opcode: this.opcode })
        .subscribe(res => {
            //this.message = (<any>res).json.data.username;
            this.token = res["token"];
            this.userData = res["user"];
            console.log(this.userData);
        });
    //console.log(this.userData);
}

Did add these to info.plist but still not working:
NSAppTransportSecurity

NSExceptionDomains

yourdomain.com


NSIncludesSubdomains


NSTemporaryExceptionAllowsInsecureHTTPLoads


NSTemporaryExceptionMinimumTLSVersion
TLSv1.1


when I do the request I get the error below for ios:

CONSOLE ERROR [native code]: ERROR ERROR {
“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”: 1298,
“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:1298: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:264:26\nrun@file:///app/tns_modules/tns-core-modules/application/application.js:284:10\nbootstrapNativeScriptApp@file:///app/tns_modules/nativescript-angular/platform-common.js:157:26\nbootstrapApp@file:///app/tns_modules/nativescr

Please help!


#2

Did you try running a clean build after updating your info plist?