How to set encoding?

32 views Asked by At

I make a request to Kaggle API:

public static void main(String[] args) {
        String datasetSlug = "cristaliss/ultimate-book-collection-top-100-books-up-to-2023";
        String kaggleUsername = "myUsername";
        String kaggleKey = "myKey";

        HttpClient httpClient = HttpClients.createDefault();
        String apiUrl = "https://www.kaggle.com/api/v1/datasets/download/" + datasetSlug;

        HttpGet request = new HttpGet(apiUrl);
        request.setHeader("Authorization", "Basic " + java.util.Base64.getEncoder().encodeToString((kaggleUsername + ":" + kaggleKey).getBytes()));
        request.setHeader("Accept-Charset", "UTF-8");

        try {
            HttpResponse response = httpClient.execute(request);
            String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);

            System.out.println("Content of the dataset:");
            System.out.println(responseBody);
        } catch (Exception e) {
            e.printStackTrace();
        }}

I'm getting this:enter image description here

How to get the output in the right encoding?

0

There are 0 answers