Просмотр исходного кода

更新 WebRequest 的 download 方法

reghao 2 лет назад
Родитель
Сommit
7aca27f9cf

+ 1 - 1
jdk/src/main/java/cn/reghao/jutil/jdk/http/WebClient.java

@@ -73,6 +73,6 @@ public class WebClient implements WebRequest {
     }
 
     @Override
-    public void download(String url, String dir) throws IOException {
+    public void download(String url, String referer, String dir) throws IOException {
     }
 }

+ 1 - 1
jdk/src/main/java/cn/reghao/jutil/jdk/http/WebRequest.java

@@ -15,5 +15,5 @@ public interface WebRequest {
     WebResponse postFormData(String url, Map<String, String> formData);
     WebResponse postJson(String url, String json);
     WebResponse upload(String url, UploadParam uploadParam);
-    void download(String url, String filePath) throws IOException;
+    void download(String url, String referer, String filePath) throws IOException;
 }

+ 3 - 1
tool/src/main/java/cn/reghao/jutil/tool/http/DefaultWebRequest.java

@@ -197,9 +197,11 @@ public class DefaultWebRequest extends BaseWebRequest implements WebRequest {
         }
     }
 
-    public void download(String url, String filePath) throws IOException {
+    @Override
+    public void download(String url, String referer, String filePath) throws IOException {
         HttpGet get = new HttpGet(url);
         get.setHeader("User-Agent", UserAgents.getDesktopAgent());
+        get.setHeader("Referer", referer);
         long start = System.currentTimeMillis();
         try (CloseableHttpResponse response = client.execute(get)) {
             int statusCode = response.getStatusLine().getStatusCode();