Делаю post запрос для отладки приложения, в ответ получаю bytearray как его отобразить хоть где-нибудь? Если я пытаюсь отобразить его в textview то у меня получается краш.
String myURL = "http://s92640jz.bget.ru/register.php";
String params = "login=user123&open_key=rgh24sfs3efs234dir&key_size=4096";
byte[] data = null;
InputStream is = null;
try {
URL url = new URL(myURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Content-Length", "" + Integer.toString(params.getBytes().length));
OutputStream os = conn.getOutputStream();
data = params.getBytes("UTF-8");
os.write(data);
data = null;
conn.connect();
int responseCode= conn.getResponseCode();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
is = conn.getInputStream();
byte[] buffer = new byte[1024]; // Такого вот размера буфер
// Далее, например, вот так читаем ответ
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
baos.write(buffer, 0, bytesRead);
}
data = baos.toByteArray();
} catch (Exception e) {
} finally {
try {
if (is != null)
is.close();
} catch (Exception ex) {}
}