RestApi/v1/Authentication/RequestToken : The response language and CharSet is different

I have integrated the authentication API (https://selectapi.datascope.refinitiv.com/RestApi/v1/Authentication/RequestToken) using JAVA in our springboot application. The issue currently we are facing is with response with this API. The API response status is 200 but the language is not in English with the charSet as UTF-16. Due to this issue we are unable to extract the auth-token to make further calls to fetch data whereas we are seeing no issue while calling the above api from Postman.


Example : 1718972466027.png
We tried to convert the above response to UTF-8 charSet but the result had some unwanted characters, due to which we cannot proceed with this approach.

From Postman :

1718972700557.png


Can anyone suggest any changes that we can make in our application code to get the desired response ?

Best Answer

  • Jirapongse
    Answer ✓

    @anubhav.tyagi

    Thank you for reaching out to us.

    If the request in Postman works fine, the problem may relate to the settings in springboot. I searched in Google and found serveral results regarding the UTF8 setting in springboot.

    I tested the UTF16 charset in Java with the Unirest and could get the token properly.

            try {
                HttpResponse<JsonNode> response = Unirest.post("https://selectapi.datascope.refinitiv.com/RestApi/v1/Authentication/RequestToken")
                    .header("Prefer", "respond-async")
                .header("Content-Type", "application/json; charset=utf-16")
                .header("Accept", "application/json")
            .body("{\"Credentials\": {\r\n    \"Username\": \"<usrname>\",\r\n    \"Password\": \"<password>\"\r\n  }\r\n}".getBytes(StandardCharsets.UTF_16))
                    .asJson();
                System.out.println(response.getHeaders());
                String token = response.getBody().getObject().getString("value");
                System.out.println("Token = "+token);
                
            } catch (UnirestException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            
            }

    The output looks like this:

    1719299940447.png

    The Content-Length of the HTTP response is 812 bytes and the Content-Type is [application/json; charset=utf-16].

    The Content-Length of the HTTP response is 405 bytes when the charset is utf-8, as shown below. 1719300365938.png

Answers

  • We are integrating the authentication API in a springboot application and making call to the authentication API using RestTemplate:

    ResponseEntity<String> response = restTemplate.postForEntity(loginUrl, requestEntity1, String.class);


    Here the login url is the authentication url and request entity contains the request headers & Body

  • Thanks @Jirapongse, we had implemented this approach and the issue is now resolved