A
A
Andrew2016-01-20 16:37:01
Java
Andrew, 2016-01-20 16:37:01

What could be the reasons that when reading the response to a POST request (in Java) I get hieroglyphs?

Good day.
When reading the answer, I get the body in hieroglyphs.
I understand that the answer immediately suggests itself - the problem is in the encoding. But I have already tried all the encodings, purely for the test and for fun (after the main popular ones).
More specifically:

HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true); // пробовал передавать параметры как в теле запроса так и в параметрах в строке
connection.setRequestProperty("Host", HOST);
connection.setRequestProperty("Origin", ORIGIN);
connection.setRequestProperty("Accept-Charset", CHARSET); //CHARSET = "UTF-8";
connection.setRequestProperty("Content-Type", CONTENT_TYPE); //"application/x-www-form-urlencoded;charset=" + CHARSET;
connection.setRequestProperty("Accept-Encoding", ACCEPT_ENCODING); //"gzip, deflate"
connection.setRequestProperty("Accept-Language", ACCEPT_LANGUAGE); //"ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4"

Reading the note:
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), CHARSET));
            while ((line = reader.readLine()) != null)
            {
                result.append(line);
                result.append("\n");
            }

In advance: I tried to subtract in a different way:
DataInputStream in = new DataInputStream(connection.getInputStream());
IOUtils.copy(connection.getInputStream(), writer, "UTF-8");
And for everyone, as soon as I could find it on the net and come up with ...
The result is the same:
a5751e011daa45e7befa0975e9dd271b330a75f598274f2aa6043a1338d52342.jpg
Accordingly, when changing encodings .. only hieroglyphs change .. to other hieroglyphs ...
But the most interesting thing is that through the Postman utility in Chrome. The same request returns the answer I need (In normal form).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
X-, 2016-01-20
@AndrewSlv

maybe like this?:
BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()), CHARSET));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question