diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java index 4eadc5c9..d70bdd90 100755 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java @@ -12,6 +12,7 @@ import com.offbytwo.jenkins.model.BaseModel; import com.offbytwo.jenkins.model.Crumb; import com.offbytwo.jenkins.model.ExtractHeader; +import java.nio.charset.StandardCharsets; import net.sf.json.JSONObject; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; @@ -45,7 +46,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -298,7 +298,8 @@ public void post_form(String path, Map data, boolean crumbFlag) queryParams.add("json=" + EncodingUtils.formParameter(JSONObject.fromObject(data).toString())); String value = mapper.writeValueAsString(data); - StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_FORM_URLENCODED); + StringEntity stringEntity = new StringEntity(value, ContentType.create(ContentType.APPLICATION_FORM_URLENCODED.getMimeType(), + StandardCharsets.UTF_8)); request = new HttpPost(UrlUtils.toNoApiUri(uri, context, path) + StringUtils.join(queryParams, "&")); request.setEntity(stringEntity); } else { @@ -325,7 +326,7 @@ public void post_form(String path, Map data, boolean crumbFlag) public HttpResponse post_form_with_result(String path, List data, boolean crumbFlag) throws IOException { HttpPost request; if (data != null) { - UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(data); + UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(data,StandardCharsets.UTF_8); request = new HttpPost(UrlUtils.toNoApiUri(uri, context, path)); request.setEntity(urlEncodedFormEntity); } else { @@ -355,7 +356,7 @@ public String post_xml(String path, String xml_data, boolean crumbFlag) throws I handleCrumbFlag(crumbFlag, request); if (xml_data != null) { - request.setEntity(new StringEntity(xml_data, ContentType.create("text/xml", "utf-8"))); + request.setEntity(new StringEntity(xml_data, ContentType.create(ContentType.TEXT_XML.getMimeType(), StandardCharsets.UTF_8))); } HttpResponse response = client.execute(request, localContext); jenkinsVersion = ResponseUtils.getJenkinsVersion(response); @@ -373,7 +374,7 @@ public String post_xml(String path, String xml_data, boolean crumbFlag) throws I */ @Override public String post_text(String path, String textData, boolean crumbFlag) throws IOException { - return post_text(path, textData, ContentType.DEFAULT_TEXT, crumbFlag); + return post_text(path, textData, ContentType.create(ContentType.TEXT_PLAIN.getMimeType(), StandardCharsets.UTF_8), crumbFlag); } /**