Android Volley access http response header fields
Asked Answered
B

2

9

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

Baseburner answered 20/12, 2013 at 11:2 Comment(0)
H
26

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;
}
Hoard answered 20/12, 2013 at 11:10 Comment(1)
You are right. But volley adds some extra header kay-values. Is there a filter for getting only server headers?Suber
N
5

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.

Nocturnal answered 20/12, 2013 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.