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 {