YvCeung commented on code in PR #7904:
URL: https://github.com/apache/incubator-seata/pull/7904#discussion_r2648879126
##########
common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java:
##########
@@ -314,15 +251,46 @@ private static Request buildHttp2Request(
Request.Builder requestBuilder = new
Request.Builder().url(url).headers(headerBuilder.build());
- if ("POST".equals(method) && requestBody != null) {
+ if ("POST".equals(method)) {
+ if (requestBody == null) {
+ requestBody = RequestBody.create(new byte[0], MEDIA_TYPE_JSON);
+ }
requestBuilder.post(requestBody);
} else if ("GET".equals(method)) {
requestBuilder.get();
+ } else {
+ throw new IllegalArgumentException("Unsupported HTTP method: " +
method);
}
return requestBuilder.build();
}
+ private static String buildUrlWithParams(String url, Map<String, String>
params) {
+ if (params == null || params.isEmpty()) {
+ return url;
+ }
+ StringBuilder urlBuilder = new StringBuilder(url);
+ boolean first = !url.contains("?");
+ for (Map.Entry<String, String> entry : params.entrySet()) {
+ if (first) {
+ urlBuilder.append("?");
+ first = false;
+ } else {
+ urlBuilder.append("&");
+ }
+ try {
+ urlBuilder
+ .append(URLEncoder.encode(entry.getKey(),
StandardCharsets.UTF_8.name()))
+ .append("=")
+ .append(URLEncoder.encode(entry.getValue(),
StandardCharsets.UTF_8.name()));
+ } catch (java.io.UnsupportedEncodingException e) {
+ // UTF-8 is always supported
+ throw new RuntimeException(e);
+ }
Review Comment:
Here, java8 support is required, so the current approach has to be used
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]