問題描述
如何通過 HttpRequest 從連接的 Android 設備訪問本地 tomcat (How to access local tomcat via HttpRequest from connected Android device)
While accessing from emulator works fine with:
response = CustomHttpClient.executeHttpPost(
"http://10.0.2.2:8080/DWAP/SERVLET", postParameters);
when I write from my Android device
response = CustomHttpClient.executeHttpPost(
"http://XX.XX.XX.XX:8080/DWAP/SERVLET", postParameters);
Where xx.xx.xx.xx is my public IP I do not get access to the local server.
Is there an easy way to test the app from an Android device to access the local Tomcat or do I need to test with emulator only?
Do need to go through port-fprwarding on my router or is there another way to connect "internally" on my WLAN. (Android mobile phone <-> MAC with local Tomcat)?
參考解法
方法 1:
Try setting your computer as the DMZ of the router. This way, communication with your router (public ip) leads directly to your computer (local ip).
(by user387184、Moshe Bixenshpaner)