Android本地主机拒绝连接

时间:2016-07-03 15:45:54

标签: android apache http request

我正在与我的服务器进行Http连接,它是apache服务器。这是我的代码:

    BufferedReader in = null;
    String data = null;

    try{
        HttpClient httpclient = new DefaultHttpClient();

        HttpGet request = new HttpGet();
        URI website = new URI("http://127.0.0.1:8888/Main.php?request=2&token=N4565345");
        request.setURI(website);
        HttpResponse response = httpclient.execute(request);
        in = new BufferedReader(new InputStreamReader(
                response.getEntity().getContent()));

    }catch(Exception e){
        Log.e("log_tag", "Error in http connection "+e.toString());
    }

但是我无法做到这一点因为,我得到了下一个错误:

  

http连接错误org.apache.http.conn.HttpHostConnectException:与http://10.0.0.1:8888的连接被拒绝

如果有人可以帮我解决这个问题,我会很高兴。感谢

1 个答案:

答案 0 :(得分:0)

您正在呼叫的网址应该由您的服务器的IP引用。像这样:

URI website = new URI("http://yourIp/Main.php?request=2&token=N4565345");