0

I would like to know how to get my Android app being simulated on an external device to communicate with a local API server running on my machine.

The app is using cordova and being run on an Android device using USB connection. I am running an API server locally.

Using my machine's IP address, I am trying to talk to the API server via HTTP calls within the app. But I get 404 errors in the debugger.

POST http://myIP:8083/api/login 404 (Not Found)

The API server is running and accessible. I have confirmed it by accessing it from the device's web browser. My hunch is that I have to whitelist my IP somewhere. But I am not sure. Any suggestions?

Using Cordova 5.3.3. Testing on LGE Nexus 5 Android 4.4.4 (API 19).

mc9
  • 6,121
  • 13
  • 49
  • 87
  • On the surface it suggests that the API server is not running. But as you can read in the question, it is running and accessible. – mc9 Oct 27 '15 at 06:10
  • But you did not answer my question: what is not found? – greenapps Oct 27 '15 at 06:11
  • it means what I am looking for is not there. What are you trying to tell me? – mc9 Oct 27 '15 at 06:13
  • 404 means Page Not Found. It does not mean Server Not Found. Now who is generating that message? Well the server is telling you that it could not find the requested page. So you reached your server. – greenapps Oct 27 '15 at 06:14
  • This is from my chrome debugger: `POST http://myIP:8083/api/login 404 (Not Found)` It seems like server not found. Am I wrong? – mc9 Oct 27 '15 at 06:15
  • I can access this endpoint via `POST` using chrome extensions making API calls. – mc9 Oct 27 '15 at 06:17
  • Well i really don't know what chrome debugger does. I was referring to http error code 404. – greenapps Oct 27 '15 at 06:17
  • Thanks for trying to help. But 404 Not Found in this case means the app could not reach the server. Trying with some invalid IP addresses gives the same error. – mc9 Oct 27 '15 at 06:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93444/discussion-between-mikec-and-greenapps). – mc9 Oct 27 '15 at 06:21

1 Answers1

0

Resolved by using https://github.com/apache/cordova-plugin-whitelist plugin and adding <meta http-equiv="Content-Security-Policy" ...> in <head> of index.html file.

For more info, read https://github.com/apache/cordova-plugin-whitelist#content-security-policy.

mc9
  • 6,121
  • 13
  • 49
  • 87