【发布时间】:2020-11-07 23:54:37
【问题描述】:
我正在尝试使用 volley 从本地机器上的 android studio 连接到 django rest 框架服务器。我尝试在命令行上使用 0.0.0.0:8000 运行服务器,并在 settings.py 中添加了 ALLOWED_HOST=[*]。
android studio 中的错误消息
com.android.volley.NoConnectionError: java.net.ConnectException: Failed to connect to /0.0.0.0:8000
下面是安卓客户端代码
P.S:- 包括所有的导入库。
String URL= "http://0.0.0.0:8000/api/userdata/";
RequestQueue requestQueue = Volley.newRequestQueue(this);
JsonObjectRequest objectRequest = new JsonObjectRequest(
Request.Method.GET,
URL,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("Response:",response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Response:",error.toString());
}
}
);
【问题讨论】:
-
你的模拟器和你的机器有不同的网络,stackoverflow.com/questions/5528850/…
-
我正在通过 USB 使用我的手机。如何解决这个问题?
标签: android django django-rest-framework