Hi,
We created the application using ionic 3.0. We are not building through Cordova but just running the app by ionic serve, like a web application.
Able to access the application in the browser but having an issue when access through a mobile browser.
Request and Response details:
URL: http://demo.test.com:8081/accounts/api/authentication/token
Request Method: POST
Request Header as : X-Api-Key=b4dbbd20-d3ab-11e8-a63f-4b1153c47651
Response (Laptop): Able to get the response
Response (Mobile): Getting error: Response with Status:0 for URL:null
Sample code:
In service class:
public anonymouslogin(apiKey):Observable {
let body = {
};
if (apiKey === null) {
return Observable.throw("Please insert account.");
} else {
let url = AuthServiceProvider.LOGIN_URL_APIEY;
let headers = new Headers(
{
"X-Api-Key": localStorage.getItem("apikey")
});
let options = new RequestOptions({ headers: headers });
alert("Initiated Post Request (in mobile not seeing any alert after this");
return this.http.post(url, body, options)
.map(response => {
alert('success');//This alert not coming desktop but not in mobile.
var temp = response.json();
return true;
},
(error) =>
{
alert('Failure');//This alert not coming in mobile even if get error.
return false;
}
);
}
}
In component:
this.auth.anonymouslogin(localStorage.getItem(“apikey”))
.subscribe(allowed => {
alert(‘Login success’);
},
(error) =>
{
alert(“This is error displaying in the mobile only”+error);
//Error objct as like this. ‘Response with Status:0 for URL:null’
}
);
Not sure about the reason why this breaking in mobile.Same issue in both Android and IOS device.