问题
I'm trying to implement http/1.0 but i have an issue loading images. I am able to load text files but i can't load any images. When i add the filereader content to a string and print to console it's not empty but gibberish like seen in the request below. The response when using google chromes built network packet analyze tool says "failed to load ressource". I don't get any errors but it just shows an empty black page (google chrome) when trying to load a single image also.
These is an example request:
HTTP/1.0 200 OK
Content-type: image/jpeg
Content-length: 58309
Date: Sat, 28 Nov 2020 16:02:45 GMT
��sf|���V��yn�����]3��B��� .......
This is my method that reads the files/image that gets returned to client:
public String readUri(String reqUri) { // image.png fx.
// check if file exist
reqFile = new File(reqUri);
if (reqFile.exists() && reqFile.isFile()) {
try {
reader = new BufferedReader(new FileReader(reqUri,StandardCharsets.UTF_8));
while ((fileLineReader = reader.readLine()) != null) {
fileContent.append(fileLineReader);
}
reader.close();
} catch (IOException e) {
System.out.println("error");
}
returnFile = fileContent.toString();
}
return returnFile;
}
The java documentation says i should use InputStreamReader for raw bytes but neither this works. https://docs.oracle.com/javase/7/docs/api/java/io/FileReader.html The above is then sent back to the socket to reply to the browser request
来源:https://stackoverflow.com/questions/65117548/loading-image-over-http-1-0