[英]Base64 image data is not getting in android
我使用HTTPURLConnection
連接到服務器,我的響應包含Base64
圖像數據。 當嘗試使用getInputStream
讀取響應時,它沒有讀取完整的響應,介於兩者之間。 我的響應包含JSON格式的對象列表,每個對象包含BASE64圖像數據。 嘗試從第一個對象讀取第一個圖像數據時讀取中斷。 雖然它沒有顯示任何錯誤,但它會顯示到圖像數據的一半。我如何得到完整的響應? 這是我的代碼
InputStream is = httpURLConnection.getInputStream();
byte[] b = new byte[1024];
StringBuffer buffer=new StringBuffer();
while ( is.read(b) != -1){
buffer.append(new String(b));
System.out.println("Read= "+is.read());
}
System.out.println(buffer);
您是否嘗試過Google的示例代碼?
URL url = new URL("http://www.android.com/");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
} finally {
urlConnection.disconnect();
}
其中readStream
是您自己的方法。
從BufferedInputStream
讀取更容易,更快捷。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.