Я использовал Volley JSONArray запросить его прямой ответ об ошибке
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()); }
Поскольку вы получаете ответ HTML или произошла ошибка, а не массив JSON, необходимо проверить серверную часть.