Getting garbled response when invoking Java API deployed on Windows server using jodd.http, despite specifying UTF-8 encoding

29 views Asked by At

I'm encountering an issue when remotely invoking a Java API deployed on a Windows server. While I can successfully make the call using Apipost(A software similar to Postman) and receive data encoded in UTF-8 without any garbled characters, I face a problem when invoking it using the following code snippet:

public static String post(String url, String jsonStr) {
    HttpResponse resp = HttpRequest.post(url)
            .connectionTimeout(60000)
            .timeout(60000)
            .contentType("application/json", StandardCharsets.UTF_8.toString())
            .bodyText(jsonStr, "application/json", "utf-8")
            .charset(StandardCharsets.UTF_8.toString())
            .send();
    resp.charset(StandardCharsets.UTF_8.toString());
    return resp.bodyText();
}

I'm using jodd.http for this purpose, and here's the Maven dependency:

<dependency>
    <groupId>org.jodd</groupId>
    <artifactId>jodd-http</artifactId>
    <version>6.3.0</version>
</dependency>

The following image is a screenshot of me calling the API using Apipost(A software similar to Postman). enter image description here enter image description here The following is a screenshot of the log for my service invocation interface. enter image description here Despite specifying UTF-8 encoding, I receive garbled text in the response. What could be causing this issue?

I expected that by specifying UTF-8 encoding and ensuring proper encoding on the server side, the response would display correctly without any garbled characters. However, despite these efforts, I continued to receive garbled text in the response.I'm hoping to receive assistance from experts in resolving this issue. ( ̄▽ ̄)~*

0

There are 0 answers