【发布时间】:2017-01-19 07:57:26
【问题描述】:
我在我的 android 应用程序中使用 volley 来发出 HTTP GET 请求。我收到以下错误 -
(HTTPLog)-Static: isSBSettingEnabled false
(HTTPLog)-Static: isSBSettingEnabled false
BasicNetwork.performRequest: Unexpected response code 500 for D/LOG ENTRY(21952): com.android.volley.ServerError
当我使用 REST 客户端发出相同的 HTTP 请求时,它是成功的。
我的 Volley 请求代码是 -
RequestQueue queue2 = Volley.newRequestQueue(appContext);
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET,url,null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("Response",response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("LOG ENTRY",error.toString());
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("clientSecret", appContext.getString(R.string.username));
return headers;
}
};
// Add the request to the RequestQueue.
queue2.add(req);
请您帮忙找出错误发生的原因
【问题讨论】:
-
您使用的链接是什么?错误 500 是内部服务器错误(错误在服务器端)。
-
我也这么认为,但是当我在 REST API 客户端上使用相同的链接时,它可以工作,所以不确定问题是什么
-
我发送了 10 个类似的 HTTP 请求,每次对于其中一些随机我收到此错误,而对于其他我没有。当我做 getCause() 或 getStackTrace() 它是空的
-
你试过 JsonArrayRequest 而不是 JsonObjectRequest 吗?
-
我做了,得到同样的错误
标签: android http android-volley