I am working on a project that allows Android Built Ionic version 2 app to create user and authenticate to a Django dev site through Django Rest API.
The authentication works when using ionic serve
this was achieved through the use of Cross Origin Resource Sharing (installed as google chrome plugin).
As I’ve tried to run the application on an actual android device, the authentication fails (HTTP 404: URL not found) when using the app but the localhost can be accessed through browser of the same device (through 192.168.22.4:80).
Details:
My current private IP address is 192.168.22.4
and the dev site is currently being served at the localhost port 80 through Wamp Apache Server.
Here is the code fragment of my http request on Ionic App (signup):
let headers = new Headers();
headers.append('Content-Type','application/json');
this.http.post("http://192.168.22.4:80/api-user-create", JSON.stringify(this.postData), {headers: headers}).subscribe(res => {
console.log(res.json());
this.showAlert();
}, (err) => {
console.log(err);
});
Applied Solutions:
These are the steps that I have tried but still failed to connect to the localhost:
- Ensure that the app is allowed to access to WiFi connection, verify whether my IP address is correct, turned off my firewall and even my antivirus. I have also enabled network discovery on my dev server.
- Use proxy server (ngrok) and edit Ionic request
- Enable CORS on Apache Server and edit Ionic request
- Edit Ionic request code. I have tried to changed 192.168.22.4:80 to:
192.168.22.4
127.0.0.1:80
127.0.0.1
localhost:80
localhost
10.0.2.2
10.0.2.2:80
Has anyone encountered this problem and solved it?