Skip to content

Commit

Permalink
Force UTF-8 for StringEntity encoding (microsoft#33)
Browse files Browse the repository at this point in the history
The default behavior is to encode as plain text w/ ISO-8859-1, so non-Latin characters are miscoded.
  • Loading branch information
cthrash authored and huxuan committed Apr 3, 2018
1 parent a55b5d8 commit 6b4eb24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ClientLibrary/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ group = "com.microsoft.projectoxford"
// Artifact name is the name of the technology
archivesBaseName = "face"
// Update your version
version = "1.4.1"
version = "1.4.2"

// Upload artifacts to maven central repository staging servers
uploadArchives {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Map;

Expand Down Expand Up @@ -119,8 +120,8 @@ private Object get(String url) throws ClientException, IOException {
private Object patch(String url, Map<String, Object> data, String contentType) throws ClientException, IOException {
HttpPatch request = new HttpPatch(url);
request.setHeader(HEADER_KEY, mSubscriptionKey);
String json = mGson.toJson(data).toString();
StringEntity entity = new StringEntity(json);
String json = mGson.toJson(data);
StringEntity entity = new StringEntity(json, StandardCharsets.UTF_8.toString());
request.setEntity(entity);
request.setHeader(CONTENT_TYPE, APPLICATION_JSON);
HttpResponse response = mClient.execute(request);
Expand Down Expand Up @@ -158,8 +159,8 @@ private Object post(String url, Map<String, Object> data, String contentType) th
request.setHeader(HEADER_KEY, this.mSubscriptionKey);

if (!isStream) {
String json = mGson.toJson(data).toString();
StringEntity entity = new StringEntity(json);
String json = mGson.toJson(data);
StringEntity entity = new StringEntity(json, StandardCharsets.UTF_8.toString());
request.setEntity(entity);
} else {
request.setEntity(new ByteArrayEntity((byte[]) data.get(DATA)));
Expand All @@ -186,8 +187,8 @@ private Object put(String url, Map<String, Object> data) throws ClientException,
HttpPut request = new HttpPut(url);

request.setHeader(HEADER_KEY, mSubscriptionKey);
String json = mGson.toJson(data).toString();
StringEntity entity = new StringEntity(json);
String json = mGson.toJson(data);
StringEntity entity = new StringEntity(json, StandardCharsets.UTF_8.toString());
request.setEntity(entity);
request.setHeader(CONTENT_TYPE, APPLICATION_JSON);
HttpResponse response = mClient.execute(request);
Expand Down Expand Up @@ -217,8 +218,8 @@ private Object delete(String url, Map<String, Object> data) throws ClientExcepti
response = mClient.execute(request);
} else {
HttpDeleteWithBody request = new HttpDeleteWithBody(url);
String json = mGson.toJson(data).toString();
StringEntity entity = new StringEntity(json);
String json = mGson.toJson(data);
StringEntity entity = new StringEntity(json, StandardCharsets.UTF_8.toString());
request.setEntity(entity);
request.setHeader(CONTENT_TYPE, APPLICATION_JSON);
request.setHeader(HEADER_KEY, mSubscriptionKey);
Expand Down

0 comments on commit 6b4eb24

Please sign in to comment.