Friday, December 20, 2013

android Volley can't handle redirect responses for twipic images even though we do setFollowRedirect.


I think android volley can't handle redirect responses by default (?)
But, we make URLConnection, which volley uses on android 2.3 (API 9) or higher(?), handles redirects with setFollowRedirects.
You can override HurlStack.createConnection() or simply call HttpURLConnection.setFollowRedirects().

static voidsetFollowRedirects(boolean auto)
Sets the flag of whether this connection will follow redirects returned by the remote server.
voidsetInstanceFollowRedirects(boolean followRedirects)
Sets whether this connection follows redirects.

https://android.googlesource.com/platform/frameworks/volley/+/master/src/com/android/volley/toolbox/HurlStack.java
  1.     protected HttpURLConnection createConnection(URL url) throws IOException {
  2.         return (HttpURLConnection) url.openConnection();
  3.     }


But, it still can't handle twipic images.
The reason why was that setFollowRedirects doesn't allow HTTP <--> HTTP redirects.

http://developer.android.com/reference/java/net/HttpURLConnection.html

Response Handling

HttpURLConnection will follow up to five HTTP redirects. It will follow redirects from one origin server to another. This implementation doesn't follow redirects from HTTPS to HTTP or vice versa.


If you still want to fix it, modify the source code of the volley, please.

http://stackoverflow.com/questions/17481964/android-volley-to-handle-redirect
http://stackoverflow.com/questions/19787999/unexpected-response-code-302-for-volley-image-request

No comments:

Post a Comment