Hello,
I am trying to read Json response on specific HTTP status code using volley error method. Yet I am unable to read JSON response following this way it gives me HTML code while returning the response.
//Doing this by Using VolleyError class.
String responseBody = new String(error.networkResponse.data, “utf-8”);
// Log.i(“DataX:”, responseBody);
// JSONObject data = new JSONObject(responseBody);
// Log.i(“Data:”, error.networkResponse.data.toString());
If anyone can provide any help with this.
This may be related.
frappe:develop
← gavindsouza:response-type-json
opened 05:58AM - 29 Apr 21 UTC
**Before**
If header `'Accept: application/json'` isn't set, the failure resp… onses to `/api/` endpoints are HTML. Success responses are of type JSON.
![Screenshot 2021-04-29 at 11 10 42 AM](https://user-images.githubusercontent.com/36654812/116506835-b43af900-a8db-11eb-8e26-38cdd08f16a1.png)
![Screenshot 2021-04-29 at 11 11 29 AM](https://user-images.githubusercontent.com/36654812/116506839-b604bc80-a8db-11eb-8b20-47ae3ad914c1.png)
**After**
If the header `Accept` isn't set, the failure responses to `/api/` endpoints are of type JSON. Success responses are of type JSON as well. To receive responses in HTML, you can set the header `'Accept: text/html'`, though any `text/` mime type will only return an HTML response at this point.
![Screenshot 2021-04-29 at 11 07 14 AM](https://user-images.githubusercontent.com/36654812/116506829-b1d89f00-a8db-11eb-9f8d-deeeac37474d.png)
![Screenshot 2021-04-29 at 11 11 36 AM](https://user-images.githubusercontent.com/36654812/116506843-b735e980-a8db-11eb-8652-04d9a1232f9c.png)
If your ERPNext server is not upgraded to include the code in PR, then use “Accept” header like mentioned in PR and try
@revant_one Thank you so much for your input on this. Yes, It was because of the headers. I am able to fetch the JSON with other status code as well.