I'm using the latest Volley library and I'm having issues when my api is returning a 204 with no body in the response. It seems that the following code in BasicNetwork.java isn't working as expected:
// Some responses such as 204s do not have content. We must check.
if (httpResponse.getEntity() != null) {
responseContents = entityToBytes(httpResponse.getEntity());
} else {
// Add 0 byte response as a way of honestly representing a
// no-content request.
responseContents = new byte[0];
}
the result from getEntity is never null for me, but it is empty. I've made sure that my API is returning nothing by checking curl and postman (just to be extra sure i'm not going crazy). Has anyone else has such an issue?
For now I've just changed that if to:
if (statusCode != HttpStatus.SC_NO_CONTENT && httpResponse.getEntity() != null)
which I know isn't solving the root cause, but I want to make sure that I'm not missing anything obvious before diving deeper into this problem.
Thanks!
EDIT: Sorry, I forgot to mention that the actual problem was that a timeout exception occurs whilst in the method entityToBytes, which is strange since there is no body to retrieve.
Also, i'm not using an actual fully functioning webservice API, as it's not available yet. Instead i'm connecting to a mocked out webservice on apiary, but i don't see how apiary could be the problem.
entityToBytes
appears to return a 0-length byte[] when there is no content – AimgetEntity()
was null I was returning a blank entity. You issue may be similar. – BurnhamperformRequest
method of your implementation ofHttpStack
if it's responsegetEntity
returnsnull
then volley should work fine as it is. If like me you are converting between old and new apache libraries or doing other processing, you may be adding an empty entity. – Burnham