Skip to content

Commit

Permalink
feat: Updated core/src/main/java/com/tlcsdm/core/u
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Apr 9, 2024
1 parent 07a867d commit 2079408
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion core/src/main/java/com/tlcsdm/core/util/HttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ public static String doPost(String url, Map<String, String> header, String body)
return execute(builder, StandardCharsets.UTF_8);
}

/**
* PUT请求.
*/
public static String doPut(String url, Map<String, String> header, String body) {
HttpRequest.BodyPublisher bodyPublisher = HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8);
var builder = HttpRequest.newBuilder().uri(URI.create(url)).PUT(bodyPublisher);
buildHeader(header, builder);
return execute(builder, StandardCharsets.UTF_8);
}

/**
* DELETE请求.
*/
public static String doDelete(String url, Map<String, String> header) {
var builder = HttpRequest.newBuilder().uri(URI.create(url)).DELETE();
buildHeader(header, builder);
return execute(builder, StandardCharsets.UTF_8);
}

/**
* form表单.
*/
Expand Down Expand Up @@ -93,7 +112,7 @@ private static void buildHeader(Map<String, String> header, HttpRequest.Builder
builder.setHeader(key, header.get(key));
}
}
builder.setHeader("Content-Type", "application/json");
// The Content-Type is set conditionally in the calling methods
builder.setHeader("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.50");
}
Expand Down

0 comments on commit 2079408

Please sign in to comment.