From 63df12a22db271d8f16bf68b0502e2b6b9b70c16 Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Tue, 29 Aug 2023 15:28:39 +0900 Subject: [PATCH] =?UTF-8?q?content-type=20header=20->=20charset=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/foundation/web/WebClient.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/cokr/xit/foundation/web/WebClient.java b/src/main/java/cokr/xit/foundation/web/WebClient.java index 26eb940..673530e 100644 --- a/src/main/java/cokr/xit/foundation/web/WebClient.java +++ b/src/main/java/cokr/xit/foundation/web/WebClient.java @@ -80,12 +80,6 @@ import cokr.xit.foundation.data.JSON; * @author mjkhan */ public class WebClient { - private static final String - FORM_DATA = "application/x-www-form-urlencoded", - JSON_DATA = "application/json", - XML_DATA = "text/xml"; -// MULTIPART = "multipart/form-data"; - private HttpClient.Version version = HttpClient.Version.HTTP_2; private Duration timeout = Duration.ofSeconds(30); private Authenticator authenticator; @@ -274,7 +268,6 @@ public class WebClient { private String uri; private boolean async, -// json, download; private Charset charset = StandardCharsets.UTF_8; private LinkedHashMap headers; @@ -437,10 +430,10 @@ public class WebClient { HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(uri + queryString)) .GET(); -/* - if (json) - builder.header("Accept", JSON_DATA); -*/ + ContentType contentType = contentType(); + if (contentType != null) + builder.header("Content-Type", contentType.type + "; charset=" + charset); + if (headers != null) headers.forEach((k, v) -> builder.header(k, v)); @@ -476,10 +469,8 @@ public class WebClient { ContentType contentType = contentType(); HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(uri)); if (contentType != null) - builder.header("Content-Type", contentType.type); + builder.header("Content-Type", contentType.type + "; charset=" + charset); builder.POST(bodyPublisher(contentType)); -// .header("Content-Type", !json ? FORM_DATA : JSON_DATA) -// .POST(HttpRequest.BodyPublishers.ofString(!json ? getParams() : inJSON())); if (headers != null) headers.forEach((k, v) -> builder.header(k, v)); @@ -517,7 +508,7 @@ public class WebClient { if (value instanceof Path) { Path path = (Path)value; String mimeType = Files.probeContentType(path); - byteList.add(("\"" + entry.getKey() + "\"; filename=\"" + path.getFileName() + "\"\r\nContent-Type: " + mimeType + "\r\n\r\n").getBytes(StandardCharsets.UTF_8)); + byteList.add(("\"" + entry.getKey() + "\"; filename=\"" + path.getFileName() + "\"\r\nContent-Type: " + mimeType + "\r\n\r\n").getBytes(charset)); byteList.add(Files.readAllBytes(path)); byteList.add("\r\n".getBytes(charset)); } else {