预设视频相关内容
This commit is contained in:
@@ -5,18 +5,32 @@ import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import com.yutou.nas.utils.Interfaces.NetworkInterface;
|
||||
import com.yutou.nas.utils.StringUtils;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Set;
|
||||
|
||||
public class HttpTools {
|
||||
public static final String serverKey="zIrsh9TUZP2lfRW753PannG49E7VJvor";
|
||||
public static String get(String url) {
|
||||
private static final int HttpRequestIndex=3;
|
||||
|
||||
public static String get(String url){
|
||||
return new HttpTools().http_get(url,0);
|
||||
}
|
||||
public static void post(final String url, final byte[] body, final NetworkInterface networkInterface){
|
||||
new HttpTools().http_post(url, body,0, networkInterface);
|
||||
}
|
||||
public static File syncDownload(final String url, final String saveName){
|
||||
return new HttpTools().http_syncDownload(url, saveName);
|
||||
}
|
||||
public String http_get(String url,int index) {
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestProperty("User-Agent", getExtUa());
|
||||
connection.connect();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
StringBuilder str = new StringBuilder();
|
||||
String tmp;
|
||||
@@ -27,12 +41,16 @@ public class HttpTools {
|
||||
connection.disconnect();
|
||||
return str.toString();
|
||||
} catch (Exception e) {
|
||||
if(index<HttpRequestIndex){
|
||||
return http_get(url,++index);
|
||||
}
|
||||
System.err.println("error url = "+url);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void post(final String url, final byte[] body, final NetworkInterface networkInterface) {
|
||||
public void http_post(final String url, final byte[] body,final int index, final NetworkInterface networkInterface) {
|
||||
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@@ -74,7 +92,11 @@ public class HttpTools {
|
||||
connection.disconnect();
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if(index<HttpRequestIndex){
|
||||
http_post(url, body, index+1, networkInterface);
|
||||
}else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
@@ -189,7 +211,7 @@ public class HttpTools {
|
||||
}).start();
|
||||
}
|
||||
|
||||
public synchronized static File syncDownload(final String url, final String saveName) {
|
||||
public synchronized File http_syncDownload(final String url, final String saveName) {
|
||||
if(StringUtils.isEmpty(url)){
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user