Fixed url redirect
This commit is contained in:
parent
7915a13a83
commit
d4bdcc6d09
2 changed files with 20 additions and 11 deletions
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
|
|
@ -1,8 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="EntryPointsManager">
|
|
||||||
<entry_points version="2.0" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
import com.ericsson.uecontrol.gui.MainActivity;
|
import com.ericsson.uecontrol.gui.MainActivity;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
|
@ -12,6 +11,7 @@ import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ezivkoc on 2014-09-18.
|
* Created by ezivkoc on 2014-09-18.
|
||||||
|
|
@ -23,18 +23,30 @@ public class UrlUtil {
|
||||||
if(!isNetworkAvailable())
|
if(!isNetworkAvailable())
|
||||||
throw new IOException("No Data Network Available");
|
throw new IOException("No Data Network Available");
|
||||||
|
|
||||||
final URLConnection connection = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
connection.setConnectTimeout(5000);
|
connection.setConnectTimeout(5000);
|
||||||
connection.setReadTimeout(3000);
|
connection.setReadTimeout(3000);
|
||||||
connection.setUseCaches(false);
|
connection.setUseCaches(false);
|
||||||
|
|
||||||
/*new Thread(new Runnable() {
|
// Handle redirects
|
||||||
public void run() {
|
if (connection instanceof HttpURLConnection) {
|
||||||
try{Thread.sleep(5000);}catch(Exception e){};
|
HttpURLConnection httpConn = (HttpURLConnection) connection;
|
||||||
log.error("Force disconnect URLConnection");
|
httpConn.setInstanceFollowRedirects(false); // Make the logic below easier to detect redirections
|
||||||
connection.
|
|
||||||
|
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();
|
connection.connect();
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue