Php 错误:org.apache.http.conn.HttpHostConnectException:连接到http://10.0.2.2:8080 拒绝

Php 错误:org.apache.http.conn.HttpHostConnectException:连接到http://10.0.2.2:8080 拒绝,php,android,eclipse,rest,Php,Android,Eclipse,Rest,错误:org.apache.http.conn.HttpHostConnectException:连接到http://10.0.2.2:8080当Android使用php中的rest api时被拒绝,我连接到该api 我通过usb使用eclipse和android手机运行我的应用程序。我的api rest是用php编写的,使用xampp,它在端口8080上运行http://localhost:8080。Xampp与我的其他web应用程序配合使用,但Android不起作用 -此外,我的手机和电脑未

错误:org.apache.http.conn.HttpHostConnectException:连接到
http://10.0.2.2:8080
当Android使用php中的rest api时被拒绝,我连接到该api

我通过usb使用eclipse和android手机运行我的应用程序。我的api rest是用php编写的,使用xampp,它在端口8080上运行
http://localhost:8080
。Xampp与我的其他web应用程序配合使用,但Android不起作用

-此外,我的手机和电脑未连接到同一网络。 -RESTAPI可以在没有internet的情况下工作吗

我在android中的代码如下:

 private class TareaWSInsertar extends AsyncTask<String,Integer,Boolean> {
        //agregado user_id, user_fullname, user_email
        private int user_id;
        private String user_fullname;
        private  String user_email;

        protected Boolean doInBackground(String... params) {
            boolean resul = true;

            HttpClient httpClient = new DefaultHttpClient();


            HttpPost post = new HttpPost("http://10.0.2.2:8080/rest/login/");
        post.setHeader("content-type", "application/json");

        try
            {
            //Construimos el objeto cliente en formato JSON
            JSONObject dato = new JSONObject();


            dato.put("email", params[0]);
            dato.put("pwd", params[1]);

            StringEntity entity = new StringEntity(dato.toString());
            post.setEntity(entity);

                HttpResponse resp = httpClient.execute(post);
                String respStr = EntityUtils.toString(resp.getEntity());

                JSONObject respJSON = new JSONObject(respStr);

                user_id = respJSON.getInt("user_id");
                user_fullname = respJSON.getString(user_fullname);
                user_email = respJSON.getString("user_email");


                if(!respStr.equals("true"))
                    resul = false;
            }
            catch(Exception ex)
            {
                Log.e("ServicioRest","Error!", ex);
                resul = false;
            }

            return resul;
        }

            protected void onPostExecute(Boolean result) {

            if (result)
            {
             Toast.makeText(getApplicationContext(), "" + user_id+ "-" +    user_fullname + "-" + user_email, Toast.LENGTH_LONG).show();
            }
        }
    }
注意:我读到了
http://10.0.2.2
仅在使用android emulator时有效, 我使用通过usb连接的手机

但是没有任何效果,即使是我在清单中添加的


对不起,帮帮我!!,PD:我不会说英语

首先,您有一个错误:

 HttpPost post = new HttpPost ( " http:/127.0.0.1:8080/rest/login/ "); 
应该是:

HttpPost post = new HttpPost ( " http://127.0.0.1:8080/rest/login/ ");
下一步,如果手机没有连接到您的计算机网络,它将永远不会连接到您的本地服务器或您的计算机


如果您家中有wifi连接,请检查运行xampp的计算机的ip地址,并将其替换为
localhost
。如果没有wifi连接,并且您的计算机连接到调制解调器(没有路由器),则只需检查您的ip地址并将其替换为
localhost

我通过在url中从cmd->ipconfig写入我的ip地址来解决此问题:


HttpPost=新的HttpPost(“”)

http:/127.0.0.1:8080/rest/login/
这是打字错误吗?这是另一个问题:)。请接受这个,换一个,我会很乐意的help@slowFly,请提出一个新问题。然后在评论中添加链接。我很乐意帮助你。
HttpPost post = new HttpPost ( " http://127.0.0.1:8080/rest/login/ ");