Dha*_*dra 99 localhost httpconnection android-emulator androidhttpclient
我在localhost中创建了一个php脚本,我正在连接它,httpClient但是我遇到了问题.
请告诉我如何从模拟器连接到localhost的php文件?
小智 287
10.0.2.2访问您的实际机器.如您所知,当您使用模拟器时,localhost(127.0.0.1)指的是设备自己的环回服务,而不是您所期望的机器上的环回服务.
您可以使用10.0.2.2访问您的实际计算机,它是一个别名设置,以帮助开发.
Chr*_*eve 22
This is what finally worked for me.
Configure your Android emulator's proxy to use your IP address as host name and the port your backend is running on as port (in my case: 192.168.1.86:8080

Have your Android app send requests to the same URL (192.168.1.86:8080) (sending requests to localhost, and http://10.0.2.2 did not work for me)
Md *_*ury 12
谢谢@lampShaded的回答。
在您的API / URL中直接使用,http://10.0.2.2:[your port]/并在仿真器设置下添加代理地址为10.0.2.2和端口号。有关更多信息,请访问:https : //developer.android.com/studio/run/emulator-networking.html
Pra*_*ash 11
感谢此博客的作者:https : //bigdata-etl.com/solved-how-to-connect-from-android-emulator-to-application-on-localhost/
在 xml 中定义网络安全配置
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)
并设置它 AndroidManifest.xml
<application
android:networkSecurityConfig="@xml/network_security_config"
</application>
Run Code Online (Sandbox Code Playgroud)
为我解决了问题!
请参考:https : //developer.android.com/training/articles/security-config
您应该使用以下命令更改 adb 端口:
adb reverse tcp:8880 tcp:8880; adb reverse tcp:8081 tcp:8081; adb reverse tcp:8881 tcp:8881
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
64816 次 |
| 最近记录: |