0
是否可以在單個HTTP響應中包含多種響應類型?例如,JSON數據以及圖像。在單個HTTP響應中混合使用JSON數據和圖像內容
是否可以在單個HTTP響應中包含多種響應類型?例如,JSON數據以及圖像。在單個HTTP響應中混合使用JSON數據和圖像內容
嘿這是不可能設置多個MIME TYPE
到HTTPResponse
。但是你可以做的是,你可以將內容類型設置爲application/json
。並且使用json
,您可以使用BASEEncoder發送圖像。
public static String encodeToString(BufferedImage image, String type) {
String imageString = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ImageIO.write(image, type, bos);
byte[] imageBytes = bos.toByteArray();
BASE64Encoder encoder = new BASE64Encoder();
imageString = encoder.encode(imageBytes);
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
return imageString;
}
不,我認爲一個通常會在發送JSON圖像的URL,並使用JavaScript來更新「IMG」元素的「src」屬性
是的,這是可能的。不過,您可能不會在瀏覽器中使用它。 http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html –