Why is my Web API server refusing to accept calls from Android?

喜欢而已 提交于 2019-12-11 09:19:49

问题


I can access my Web API server from a Windows app without problems. From Android, though, is a different story

Why would that be?

Is "localhost" the wrong thing to use (in the URL)? Should I use the name of the computer instead?

Does the string (passed literally as "http://localhost:28642/api/Departments/GetCount?serialNum=4242") need to be verbatimized?

What is the difference between a Windows app calling a REST method, and an Android app calling the same REST method, that would cause the latter to fail (connection refused)?


回答1:


Referencing "localhost" to refer to your local machine doesn't work on the Android emulator; you need to use a special IP which the emulator will forward on to the host machine. You need to replace localhost with 10.0.2.2, as per this answer.

If you're testing this on a physical device (rather than the emulator) you'll need to use your machines IP on the local network.



来源:https://stackoverflow.com/questions/22798949/why-is-my-web-api-server-refusing-to-accept-calls-from-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!