content-type header -> charset 추가

master
mjkhan21 1 year ago
parent c5a868db2f
commit 63df12a22d

@ -80,12 +80,6 @@ import cokr.xit.foundation.data.JSON;
* @author mjkhan * @author mjkhan
*/ */
public class WebClient { 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 HttpClient.Version version = HttpClient.Version.HTTP_2;
private Duration timeout = Duration.ofSeconds(30); private Duration timeout = Duration.ofSeconds(30);
private Authenticator authenticator; private Authenticator authenticator;
@ -274,7 +268,6 @@ public class WebClient {
private String uri; private String uri;
private boolean private boolean
async, async,
// json,
download; download;
private Charset charset = StandardCharsets.UTF_8; private Charset charset = StandardCharsets.UTF_8;
private LinkedHashMap<String, String> headers; private LinkedHashMap<String, String> headers;
@ -437,10 +430,10 @@ public class WebClient {
HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(uri + queryString)) HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(uri + queryString))
.GET(); .GET();
/* ContentType contentType = contentType();
if (json) if (contentType != null)
builder.header("Accept", JSON_DATA); builder.header("Content-Type", contentType.type + "; charset=" + charset);
*/
if (headers != null) if (headers != null)
headers.forEach((k, v) -> builder.header(k, v)); headers.forEach((k, v) -> builder.header(k, v));
@ -476,10 +469,8 @@ public class WebClient {
ContentType contentType = contentType(); ContentType contentType = contentType();
HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(uri)); HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(uri));
if (contentType != null) if (contentType != null)
builder.header("Content-Type", contentType.type); builder.header("Content-Type", contentType.type + "; charset=" + charset);
builder.POST(bodyPublisher(contentType)); builder.POST(bodyPublisher(contentType));
// .header("Content-Type", !json ? FORM_DATA : JSON_DATA)
// .POST(HttpRequest.BodyPublishers.ofString(!json ? getParams() : inJSON()));
if (headers != null) if (headers != null)
headers.forEach((k, v) -> builder.header(k, v)); headers.forEach((k, v) -> builder.header(k, v));
@ -517,7 +508,7 @@ public class WebClient {
if (value instanceof Path) { if (value instanceof Path) {
Path path = (Path)value; Path path = (Path)value;
String mimeType = Files.probeContentType(path); 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(Files.readAllBytes(path));
byteList.add("\r\n".getBytes(charset)); byteList.add("\r\n".getBytes(charset));
} else { } else {

Loading…
Cancel
Save