From 81da61b828e29b7745e1382dfbbaeb685dc083ef Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 23 一月 2024 17:17:55 +0800
Subject: [PATCH] 抖音转链修改

---
 utils/src/main/java/org/yeshi/utils/HttpUtil.java |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/utils/src/main/java/org/yeshi/utils/HttpUtil.java b/utils/src/main/java/org/yeshi/utils/HttpUtil.java
index 8483bc2..960384a 100644
--- a/utils/src/main/java/org/yeshi/utils/HttpUtil.java
+++ b/utils/src/main/java/org/yeshi/utils/HttpUtil.java
@@ -46,7 +46,7 @@
 import org.yeshi.utils.entity.ProxyIP;
 
 import net.sf.json.JSONObject;
-
+import java.net.HttpURLConnection;
 public class HttpUtil {
 
     public static List<String> getUrlListFromText(String text) {
@@ -657,4 +657,53 @@
         }
         return null;
     }
+
+    public static String getLocation(String url,Map<String,String> headers, String method) {
+        HttpClient client = new HttpClient();
+        if ("GET".equalsIgnoreCase(method)) {
+            try {
+                URL uri = new URL(url);
+                // 鎵撳紑杩炴帴
+                HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
+                // 璁剧疆HTTP璇锋眰鏂规硶涓篏ET
+                connection.setRequestMethod("GET");
+
+                // 鑾峰彇鍝嶅簲鐮�
+                int responseCode = connection.getResponseCode();
+
+                if (responseCode == HttpURLConnection.HTTP_OK) {
+                    // 鑾峰彇Location瀛楁
+                    String location = connection.getHeaderField("Location");
+                    System.out.println("Location: " + location);
+                } else {
+                    System.out.println("Request failed with response code: " + responseCode);
+                }
+                // 鍏抽棴杩炴帴
+                connection.disconnect();
+            }catch(Exception e){
+                e.printStackTrace();
+            }
+            return null;
+        } else {
+            PostMethod md = new PostMethod(url);
+            if (headers != null) {
+                Iterator<String> keys = headers.keySet().iterator();
+                while (keys.hasNext()) {
+                    String key = keys.next();
+                    md.addRequestHeader(key, headers.get(key));
+                }
+            }
+            try {
+                client.executeMethod(md);
+                Header[] responseHeaders = md.getResponseHeaders();
+                return md.getResponseHeader("location").getValue();
+            } catch (HttpException e) {
+                e.printStackTrace();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+//        }
+            return null;
+        }
+    }
 }

--
Gitblit v1.8.0