通过 android 程序运行 php 脚本,并提供本地主机地址,例如
try {
url = "http://10.0.2.2:80/xxx/";
//optionally I tried
//url="http://localhost/xxx/";
//url="http://192.168.1.8/xxx/";
//url="http://127.0.0.1/xxx/";
//above all options are not working for me.
httpclient = new DefaultHttpClient();
request = new HttpGet(url);
response = httpclient.execute(request);
}
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
// Appending result to textview
result.append(line);
}
即使我检查了防火墙设置,上述所有网址也无法连接,但它不起作用。 需要帮助,我被困在这个线程中。
最佳答案
要从 Android 模拟器访问本地主机,请使用 ipconfig 中给出的 IP 地址。
打开命令提示符 -> 输入 ipconfig -> 获取 IPV4 地址...例如 192.xx...
所以你的URL =“http://192.xx.xx.xx/folder/file.php”
使用您的 Android 浏览器测试此网址...如果可以连接,那么 Android 应用程序中应该没有问题
关于java - 通过 Android 模拟器和 xampp 服务器连接到本地主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26713026/