2
我有以下代碼。當我得到答覆時,它的字符是錯誤的。我想用「UTF-8」得到答案。我如何以及在哪裏可以在下面的代碼中寫入?Http get response utf-8
由於
URL httpPost =新的URL(URL);
HttpsURLConnection connection = (HttpsURLConnection) httpPost.openConnection();
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.getOutputStream().write(params.getBytes(Charset.forName("UTF-8")));
connection.getOutputStream().flush();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
try {
String responseFromServer = response.toString();
dealsResponse = Utils.mapper.readValue(responseFromServer, GetDealsResponse.class);
} finally {
in.close();
}
獲取HTTP跟蹤。也許答案確實被打破了?在這種情況下,您需要修復服務器。 –
我跟蹤輸入行是這樣的。 {「message」:「Sunucu hatas?」,「success」:false} – serkan
需要原始HTTP跟蹤。 –