javahttpapache-commons-httpclient

Java changes Cyrillic to unicode like \uXXXX


I am making an application in Java, that will log into my school diary using web api, so I will be able to make my own UI. As the title says, Java at some moment changes the cyrillic to unicode like \uXXXX symbolds. Here is the code on the Russian Stackoverflow: https://ru.stackoverflow.com/questions/1452959/%d0%a1%d0%b5%d1%80%d0%b2%d0%b5%d1%80-%d0%be%d1%82%d0%b2%d0%b5%d1%80%d0%b3%d0%b0%d0%b5%d1%82-%d0%b7%d0%b0%d0%bf%d1%80%d0%be%d1%81. Try to translate it, to understand more. When I am sending my request to https://httpbin.org/post instead of my LOGIN_URL with cyrillic symbols it returns them transformed, if I send request with ascii symbols, I get them back, and, in the linked post I mentioned the python project, which does exactly the same thing I want. And when I modify it to make it send request to httpbin, the cyrillic symbols are returned back! What do I do to fix my java code?

P.S. Currently I am switched to okhttp3 from apache http client (same problem), but, I can go back.


Solution

  • Well, I solved my problem. It consisted not in the character encoding, but in the absence of two http headers, namely

    httpPost.setHeader("X-Requested-With", "XMLHttpRequest");
    httpPost.setHeader("Referer", Constants.BASE_URL);
    
    (added to login request)