gabrielfari / aacdecoder-android

Automatically exported from code.google.com/p/aacdecoder-android
GNU Lesser General Public License v3.0
1 stars 0 forks source link

Http Redirect 301 & 302 - Fixed #65

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi all,

I fixed a redirect problem on library. I have a stream url which redirects 
other urls, and this library "Moved Permanently ..." error on logs. I simply 
add below codes you may need same bug.

Find openConnection method and update below /**New*/ rows.

if (conn instanceof HttpURLConnection) {
                    HttpURLConnection httpConn = (HttpURLConnection) conn;
 /**New*/     HttpURLConnection.setFollowRedirects(true);
                    try {
                        // pre-KitKat returns -1:
                        if (httpConn.getResponseCode() == -1) {
                            if (!responseCodeCheckEnabled) {
                                Log.w( LOG, "No response code, but ignoring - for url " + url );
                                close = false;
                                break;
                            }
                            else {
                                Log.w( LOG, "No response code for url " + url );
                            }
/**New*/        } else if (httpConn.getResponseCode() == 
HttpURLConnection.HTTP_MOVED_TEMP || httpConn.getResponseCode() == 
HttpURLConnection.HTTP_MOVED_PERM) {
/**New*/                url = conn.getHeaderField("Location");
/**New*/                // open the new connnection again
/**New*/                conn = (HttpURLConnection) new URL(url).openConnection();
/**New*/                throw new Exception();
            } else {
                            // standard HTTP response / IcyURLConnection response
                            close = false;
                            break;
                        }
                    }
                    catch (Exception e) {
                        // KitKat throws exception:
                        // java.net.ProtocolException: Unexpected status line: ICY 200 OK
                        Log.w( LOG, "Invalid response code for url " + url + " - " + e );
                    }
                }

Original issue reported on code.google.com by fti...@gmail.com on 31 Aug 2014 at 12:41