Android Volley access http response header fields

戏子无情 提交于 2019-12-12 08:27:52

问题


How can i access HTTP header fields like ETag from a response using Volley ? With HttpUrlCoonection i just do conn.getHeaderField("ETag") and that's it.

Thanks


回答1:


You can subclass Request (or any of its subclasses) and override the parseNetworkResponse method:

@Override
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    Map<String, String> responseHeaders = response.headers;
}



回答2:


You can extend Request class. Then when you implement parseNetworkResponse(NetworkResponse response) method you can access header values in response.headers. So you can access ETag header like response.headers.get("ETag"). What I did was to then add this header value in response object like response.setETag(etag) and than I just return it in Response.success(response, null). Response object will then be delivered to deliverResponse(E response) where you can send it forward to some listener.



来源:https://stackoverflow.com/questions/20702178/android-volley-access-http-response-header-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!