add CommonRequest, FileRequest, GsonRequest, TimiRequest
This commit is contained in:
38
src/main/java/com/imyeyu/network/CommonRequest.java
Normal file
38
src/main/java/com/imyeyu/network/CommonRequest.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.imyeyu.network;
|
||||
|
||||
import org.apache.hc.client5.http.fluent.Request;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2025-07-15 14:27
|
||||
*/
|
||||
public class CommonRequest {
|
||||
|
||||
protected final Request request;
|
||||
|
||||
protected CommonRequest(Request request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public static CommonRequest wrap(Request request) {
|
||||
return new CommonRequest(request);
|
||||
}
|
||||
|
||||
public static CommonRequest get(String url) {
|
||||
return new CommonRequest(Request.get(url));
|
||||
}
|
||||
|
||||
public static CommonRequest post(String url) {
|
||||
return new CommonRequest(Request.post(url));
|
||||
}
|
||||
|
||||
public String asString() throws IOException {
|
||||
return request.execute().returnContent().asString();
|
||||
}
|
||||
|
||||
public byte[] asBytes() throws IOException {
|
||||
return request.execute().returnContent().asBytes();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user