【问题标题】:com.android.volley.NoConnectionError: java.net.ConnectException: Failed to connect to /192.168.2.100:80com.android.volley.NoConnectionError: java.net.ConnectException: 无法连接到 /192.168.2.100:80
【发布时间】:2018-11-02 09:42:39
【问题描述】:
    String URL = "http://192.168.2.100:8080/DemoRest/webapi/aliens";

    RequestQueue requestQueue = Volley.newRequestQueue(this);

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
            Request.Method.GET,
            URL,
            null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.e("Rest Response: ",response.toString());
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("Rest Response: ",error.toString());
                }
            }
    );
    requestQueue.add(jsonObjectRequest);

在这里,我尝试从我的 rest api 获取 json 数据。它在邮递员上正常工作。 bu 当我试图与 android 链接时,我收到了这个错误

【问题讨论】:

  • 你的移动网络和服务器网络一样吗?
  • 192.168.2.100 是本地网络 IP。您的 Android 设备必须在同一个本地网络中才能访问它
  • 是的,移动网络与同一个 wifi 连接.. 仍然无法正常工作 @Soham

标签: android android-volley


【解决方案1】:

here 讨论了类似的问题

如果您的服务器从您的本地主机运行并且您正在模拟器上进行测试,您必须使用documentation 中指定的正确 IP 地址

【讨论】:

  • 我正在使用具有相同 wifi 连接的 android 设备.. 但我仍然面临同样的错误
  • 使用具有相同 wifi 连接的 android 设备.. 仍然 d=面临此错误@I_of_t
【解决方案2】:
  1. 进入命令提示符,输入ipconfig
  2. 复制 ipv4 的地址并粘贴到您的 URL 中
  3. 前往清单并授予互联网权限
  4. 在应用程序标签内的清单中允许android:usesCleartextTraffic="true"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-02
    • 2016-08-13
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    相关资源
    最近更新 更多