Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http Redirect 301 & 302 - Fixed #65

Open
GoogleCodeExporter opened this issue Mar 18, 2015 · 1 comment
Open

Http Redirect 301 & 302 - Fixed #65

GoogleCodeExporter opened this issue Mar 18, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 31 Aug 2014 at 12:41

@kraizman
Copy link

Why you need throw new Exception(); after conn = (HttpURLConnection) new URL(url).openConnection();?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants