|
@@ -129,25 +129,6 @@ public class HttpUtils {
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取重定向地址
|
|
|
|
|
- * @param path 原URL地址
|
|
|
|
|
- * @return 重定向之后的地址
|
|
|
|
|
- * @throws Exception 读写异常
|
|
|
|
|
- */
|
|
|
|
|
- private static String getRedirectUrl(String path) throws Exception {
|
|
|
|
|
- HttpURLConnection conn = (HttpURLConnection) new URL(path)
|
|
|
|
|
- .openConnection();
|
|
|
|
|
- conn.setInstanceFollowRedirects(false);
|
|
|
|
|
- conn.setConnectTimeout(5000);
|
|
|
|
|
- String redirectUrl = conn.getHeaderField("Location");
|
|
|
|
|
- if(null == redirectUrl){
|
|
|
|
|
- redirectUrl = path;
|
|
|
|
|
- }
|
|
|
|
|
- return redirectUrl;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 向指定 URL 发送POST方法的请求
|
|
* 向指定 URL 发送POST方法的请求
|
|
|
*
|
|
*
|
|
@@ -250,12 +231,31 @@ public class HttpUtils {
|
|
|
return result.toString();
|
|
return result.toString();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取重定向地址
|
|
|
|
|
+ * @param path 原URL地址
|
|
|
|
|
+ * @return 重定向之后的地址
|
|
|
|
|
+ * @throws Exception 读写异常
|
|
|
|
|
+ */
|
|
|
|
|
+ private static String getRedirectUrl(String path) throws Exception {
|
|
|
|
|
+ HttpURLConnection conn = (HttpURLConnection) new URL(path)
|
|
|
|
|
+ .openConnection();
|
|
|
|
|
+ conn.setInstanceFollowRedirects(false);
|
|
|
|
|
+ conn.setConnectTimeout(5000);
|
|
|
|
|
+ String redirectUrl = conn.getHeaderField("Location");
|
|
|
|
|
+ if(null == redirectUrl){
|
|
|
|
|
+ redirectUrl = path;
|
|
|
|
|
+ }
|
|
|
|
|
+ return redirectUrl;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 将输入流中的数据写入字节数组
|
|
* 将输入流中的数据写入字节数组
|
|
|
*/
|
|
*/
|
|
|
public static byte[] inputStream2ByteArray(InputStream in) {
|
|
public static byte[] inputStream2ByteArray(InputStream in) {
|
|
|
List<Byte> byteList = new ArrayList<>();
|
|
List<Byte> byteList = new ArrayList<>();
|
|
|
- byte[] bytes = new byte[2048];
|
|
|
|
|
|
|
+ byte[] bytes = new byte[102400];
|
|
|
try {
|
|
try {
|
|
|
while (in.read(bytes) != -1) {
|
|
while (in.read(bytes) != -1) {
|
|
|
byteList.addAll(Bytes.asList(bytes));
|
|
byteList.addAll(Bytes.asList(bytes));
|