问题:如果页面在使用字符串时有图像,则将 http 消息的响应写回客户端(Web 浏览器)不会返回完整页面,所以我决定使用字节,但我仍然有同样的问题。我已经能够从请求中获取标头作为字符串并将其刷新到客户端,但我不确定如何处理该消息以确保它正确显示在 Web 浏览器上。
//This portion takes the message from the Httpurl connection inputstream
//the header has already been exttracted
//uc here represents a httpurlconnection
byte[] data = new byte[uc.getContentLength()];
int bytesRead = 0;
int offset = 0;
InputStream in = new BufferedInputStream(uc.getInputStream());
while (offset < uc.getContentLength()) {
bytesRead =in.read(data, offset, data.length-offset);
if (bytesRead == -1) break;
offset += bytesRead;