Reputation: 2155
I am currently building an ionic app, and deploying a development version on my iphone 5s. I deploy the exact same version that I deploy on my web browser. The version on the web browser works perfectly fine and does not show any errors.
However, when I run the app on my physical iphone 5s, I get the following error:
Http failure response for http://localhost:8080/get-preferences: 501 Not Implemented
This error is the result of the following function:
//Logs that 'body' and 'this.headers' are correctly created
await this.http.post('/get-preferences', body, {headers: this.headers})
.toPromise().then(data => {
//Logs everything as a correct result on web
//The following line is what displays the above error through XCode through the iphone.
}).catch(err => console.log("Error getPreferences occured: ", (<Error>err).message));
}
I googled a little bit, and adding proxies to the ionic.config.json
should have solved this for both web and iphone, but somehow the phone version does not work correctly.
This is the contents of my ionic.config.json
:
{
"name": "ionic2-app-base",
"app_id": "",
"type": "ionic-angular",
"integrations": {
"cordova": {}
},
"proxies": [
{
"path": "/get-preferences",
"proxyUrl": "http://serverIp/get-preferences"
},
{
"path": "/register-vote",
"proxyUrl": "http:/serverIp/register-vote"
},
{
"path": "/create-user",
"proxyUrl": "http://serverIp/create-user"
}
]
}
Is there anything more I have to have enabled on the iphone, such that this works?
I am using the import {HttpClient, HttpHeaders} from '@angular/common/http';
modules for the post request.
Upvotes: 2
Views: 942
Reputation: 451
I think you try to access the API from the emulator (ios / android) with an address htt: // localhost: 8080 / ... or http://127.0.0.1:8080/ ...
It's normal that it does not work localhost is the phone (even emulated).
Solution : Change your api url localhost with the ip address of your pc/server example: 192.168.xx.xx
Upvotes: 2