Skip to content

Commit

Permalink
Fix response encoding to explicitly use UTF-8 for HTTP response data (P…
Browse files Browse the repository at this point in the history
…roject-MONAI#1672)

Previously, the code used `response.getBytes()` which might rely on the platform's default charset to encode the HTTP response data, leading to inconsistent behavior across platforms.
This commit updates the code to use `response.getBytes(StandardCharsets.UTF_8)`, specifying UTF-8 encoding explicitly for processing response data. This ensures cross-platform consistency and avoids potential encoding issues.

Signed-off-by: Butui Hu <[email protected]>
  • Loading branch information
hubutui authored Apr 11, 2024
1 parent 844d6ff commit 38c19d3
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.InputStream;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -190,7 +191,7 @@ public static Document infer(String model, String image, String imageFile, Strin

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputStream inputStream = new ByteArrayInputStream(response.getBytes());
InputStream inputStream = new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8));
Document dom = builder.parse(inputStream);
return dom;
}
Expand Down

0 comments on commit 38c19d3

Please sign in to comment.