Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify post request use urf-8 encoding #444

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -298,7 +298,8 @@ public void post_form(String path, Map<String, String> 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 {
Expand All @@ -325,7 +326,7 @@ public void post_form(String path, Map<String, String> data, boolean crumbFlag)
public HttpResponse post_form_with_result(String path, List<NameValuePair> 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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

/**
Expand Down