简体   繁体   English

无法将仿真器与localhost连接? Android | 火力基地

[英]Unable to Connect Emulator with localhost ? Android | Firebase

I am trying to save emulator's token number into localhost (wampserver-phpMyAdmin). 我正在尝试将仿真器的令牌号保存到localhost(wampserver-phpMyAdmin)中。

System is giving -> Failed to connect to localhost/127.0.0.1:80 系统给出->无法连接到localhost / 127.0.0.1:80

here is full code link 这是完整的代码链接

This is the function in which i tried to register my token 这是我尝试注册令牌的功能

private  void registertoken(String token){

    Log.d(TAG, "registertoken: registion begins !!!!!!!! \n !!!!!!!!!!!!! ");

    OkHttpClient client = new OkHttpClient();
    RequestBody body = new FormBody.Builder()
            .add("Token",token)
            .build();

    Request request = new Request.Builder()
            .url("http://localhost/fcm/register.php")

            .post(body)
            .build();
   // http://fcm/register.php
    try {
        client.newCall(request).execute();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

This is PHP file I am using : 这是我正在使用的PHP文件:

<?php

if(isset($_POST["Token"])){
$token = $_POST["Token"];
$conn = mysqli_connect("localhost","root","","fcm");
$query = "INSERT INTO user(Token) Values ('$token') ON 
DUPLICATE KEY UPDATE Token = '$token' ; ";
mysqli_query($conn,$query);
mysqli_close($conn);
}
?>

localhost will point to the emulator, not your pc. 本地主机将指向仿真器,而不是您的PC。 you'll need to use the ip/dns address of the pc 您需要使用电脑的ip / dns地址

使用您计算机的本地IP地址,或者也可以尝试使用10.0.2.2代替localhost。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM