다음과 같이
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.getEntity().writeTo(baos);
byte[] bytes = baos.getBytes();
그런 다음 다른 HttpResponse
객체에 내용을 추가 할 수있는이 방법을 시도 http://commons.apache.org/proper/commons-io/
private byte[] receiveByteArrayData(HttpURLConnection httpURLConnection)
throws IOException
{
return IOUtils.toByteArray(httpURLConnection.getInputStream());
}
byte[]
데이터 전송 :
URL url = new URL("http://your.url.here:yourPortNumber/something");
HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
httpUrlConnection.setDoInput(true);
httpUrlConnection.setDoOutput(true);
httpUrlConnection.setRequestProperty("Content-Type", "application/octet-stream");
httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.setFixedLengthStreamingMode(bytes.length);
httpUrlConnection.connect();
httpUrlConnection.getOutputStream().write(bytes);
httpUrlConnection.getOutputStream().flush();
if (httpsUrlConnection.getResponseCode() == 200) //OK
{
System.out.println("successfully uploaded data");
}
httpUrlConnection.disconnect();
은 어떻게 된 ByteArray를 받는가있어? –
recv 시스템 호출 사용. – Kishore
'내 서버가 byteArray에 HttpResponse를 보냅니다.' http 서버는 http 서버이므로 텍스트, 그림 또는 문서 만 보내 게됩니다. 그것은 항상 바이트 스트림입니다. 그래서 당신은 바이트 배열로 응답에 의해 무슨 뜻인지 궁금해. – greenapps