Skip to content

Commit 5b26ceb

Browse files
Merge pull request #5 from DanailMinchev/fix-charset
Fix charset: Use "UTF-8" charset instead of default "ISO-8859-1"
2 parents 18aad2f + 3744be3 commit 5b26ceb

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ target/
1414
build/
1515
gradle.properties
1616
.gradle
17-
repo/
17+
repo/
18+
19+
# JetBrains IDEs
20+
*.iml
21+
**/.idea/

src/main/java/com/sendgrid/Client.java

+13-28
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.net.URISyntaxException;
3131
import java.net.URLEncoder;
3232

33+
import java.nio.charset.Charset;
3334
import java.util.HashMap;
3435
import java.util.List;
3536
import java.util.Map;
@@ -206,13 +207,9 @@ public Response post(Request request) throws URISyntaxException, IOException {
206207
}
207208
}
208209

209-
try {
210-
httpPost.setEntity(new StringEntity(request.body));
211-
if (request.body != "") {
212-
httpPost.setHeader("Content-Type", "application/json");
213-
}
214-
} catch (IOException ex) {
215-
throw ex;
210+
httpPost.setEntity(new StringEntity(request.body, Charset.forName("UTF-8")));
211+
if (request.body != "") {
212+
httpPost.setHeader("Content-Type", "application/json");
216213
}
217214

218215
try {
@@ -252,13 +249,9 @@ public Response patch(Request request) throws URISyntaxException, IOException {
252249
}
253250
}
254251

255-
try {
256-
httpPatch.setEntity(new StringEntity(request.body));
257-
if (request.body != "") {
258-
httpPatch.setHeader("Content-Type", "application/json");
259-
}
260-
} catch (IOException ex) {
261-
throw ex;
252+
httpPatch.setEntity(new StringEntity(request.body, Charset.forName("UTF-8")));
253+
if (request.body != "") {
254+
httpPatch.setHeader("Content-Type", "application/json");
262255
}
263256

264257
try {
@@ -299,13 +292,9 @@ public Response put(Request request) throws URISyntaxException, IOException {
299292
}
300293

301294

302-
try {
303-
httpPut.setEntity(new StringEntity(request.body));
304-
if (request.body != "") {
305-
httpPut.setHeader("Content-Type", "application/json");
306-
}
307-
} catch (IOException ex) {
308-
throw ex;
295+
httpPut.setEntity(new StringEntity(request.body, Charset.forName("UTF-8")));
296+
if (request.body != "") {
297+
httpPut.setHeader("Content-Type", "application/json");
309298
}
310299

311300
try {
@@ -345,13 +334,9 @@ public Response delete(Request request) throws URISyntaxException, IOException {
345334
}
346335
}
347336

348-
try {
349-
httpDelete.setEntity(new StringEntity(request.body));
350-
if (request.body != "") {
351-
httpDelete.setHeader("Content-Type", "application/json");
352-
}
353-
} catch (IOException ex) {
354-
throw ex;
337+
httpDelete.setEntity(new StringEntity(request.body, Charset.forName("UTF-8")));
338+
if (request.body != "") {
339+
httpDelete.setHeader("Content-Type", "application/json");
355340
}
356341

357342
try {

0 commit comments

Comments
 (0)