【问题标题】:Volley Server error<!DOCTYPE HTML PUBLIC "-//IETF/, Volley Server Error, JSONArray not converting, When Retrofit,Postman Executing urlVolley Server 错误<!DOCTYPE HTML PUBLIC "-//IETF/,Volley Server 错误,JSONArray 未转换,改造时,Postman 执行 url
【发布时间】:2018-12-13 09:58:52
【问题描述】:
  1. com.android.volley.ServerError
  2. 我使用 Volley JSONArray 请求它直接接收错误响应

    RequestQueue queue = Volley.newRequestQueue(getBaseContext());
        try {
            String url = getResources().getString(R.string.BASE_URL_SHARE) + "bank-nifty-top.txt";
            Log.d(TAG, "URL : " + url);
            JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.POST, url, null, new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    Log.d(TAG, response.toString());
    
    try {
                        Log.d(TAG, "data recieved Shares: " + response.toString());
                        if (response != null) {
                            showMarketRates(response);
                            Toast.makeText(getApplicationContext(), "request" + response.toString(), Toast.LENGTH_SHORT).show();
    
                        }
                    } catch (Exception e) {
                        Log.d(TAG, "Volley" + e.toString());
                        Log.d(TAG, "Unable to contact server. please try again");
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
    
                    checkInternet();
                    Log.d(TAG, "Error: " + error.toString());
                    NetworkResponse response = error.networkResponse;
                    if ((error instanceof ServerError) && response != null) {
                        try {
                            String res = new String(response.data, HttpHeaderParser.parseCharset(response.headers, "utf-8"));
                            Log.d(TAG, "Error: " + res);
                            if (res != null) {
                                JSONObject obj = new JSONObject(res);
                                if (obj != null) {
                                    Log.d(TAG, "Err Desc: " + obj.getString("error_description"));
                                    return;
                                }
                                return;
                            }
                            Log.d(TAG, "Unable to contact server. please try again");
                        } catch (UnsupportedEncodingException e1) {
                            Log.d(TAG, e1.toString());
                        } catch (JSONException e2) {
                            Log.d(TAG, e2.toString());
                        }
                    }
                }
            }) {
            };
            jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 2, 2.0f));
            queue.add(jsonArrayRequest);
        } catch (Exception e) {
            Log.d(TAG, e.toString());
        }
    

【问题讨论】:

  • 你能添加你给你这个错误的代码吗?你能再解释一下吗?
  • 服务器响应有问题。您收到非 JSONArray 格式的响应。
  • 你的服务器响应不是 JSON
  • 在邮递员中显示 JSON Array ,使用 Retrofit 很好,但 Volley 显示此错误,我需要 Volley
  • 解决方法是将 URL 中的 ("https://" 改为 "http://") 或 ("http://'' 改为 "https://")跨度>

标签: android api android-volley


【解决方案1】:

由于您收到的是 HTML 响应或发生错误不是 JSON 数组,您需要检查服务器端。

【讨论】:

  • 我在邮递员中检查了它的工作正常,在凌空它显示错误,我添加了代码
猜你喜欢
  • 2016-07-09
  • 1970-01-01
  • 2014-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-27
  • 1970-01-01
  • 2016-09-20
相关资源
最近更新 更多