Fixed url redirect

This commit is contained in:
Ziver Koc 2017-08-22 18:26:28 +02:00
parent 7915a13a83
commit d4bdcc6d09
2 changed files with 20 additions and 11 deletions

View file

@ -4,7 +4,6 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import com.ericsson.uecontrol.gui.MainActivity;
import org.apache.log4j.Logger;
@ -12,6 +11,7 @@ import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
/**
* Created by ezivkoc on 2014-09-18.
@ -23,18 +23,30 @@ public class UrlUtil {
if(!isNetworkAvailable())
throw new IOException("No Data Network Available");
final URLConnection connection = url.openConnection();
URLConnection connection = url.openConnection();
connection.setConnectTimeout(5000);
connection.setReadTimeout(3000);
connection.setUseCaches(false);
/*new Thread(new Runnable() {
public void run() {
try{Thread.sleep(5000);}catch(Exception e){};
log.error("Force disconnect URLConnection");
connection.
// Handle redirects
if (connection instanceof HttpURLConnection) {
HttpURLConnection httpConn = (HttpURLConnection) connection;
httpConn.setInstanceFollowRedirects(false); // Make the logic below easier to detect redirections
switch (httpConn.getResponseCode())
{
case HttpURLConnection.HTTP_MOVED_PERM:
case HttpURLConnection.HTTP_MOVED_TEMP:
String redirectSrt = URLDecoder.decode(
httpConn.getHeaderField("Location"), "UTF-8");
URL redirectURL = new URL(url, redirectSrt); // Deal with relative URLs
log.info("HTTP Redirect: From: "+url+", to: "+redirectURL);
httpConn.disconnect();
connection = getURLConnection(redirectURL);
}
}).start();*/
}
connection.connect();
return connection;