From 66c4c910dcfe5d955103376c4c4afc685557dc55 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 23 十一月 2023 18:13:02 +0800 Subject: [PATCH] 2023年11月23日18:11:10 --- app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java | 35 +++++++++++++++++++++++++++++------ 1 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java b/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java index ae5e6f3..10b7485 100644 --- a/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java +++ b/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java @@ -6,6 +6,8 @@ import com.hdl.photovoltaic.other.HdlFileLogic; +import java.io.BufferedInputStream; +import java.io.FileInputStream; import java.io.IOException; import java.util.Date; import java.util.HashMap; @@ -70,13 +72,10 @@ String fileName = ((HTTPSession) session).getUri(); String data = ""; if (fileName.equals(HdlFileLogic.getInstance().getDriveRootPath())) { - data = HdlFileLogic.getInstance().readFile(fileName); - } //鍝嶅簲瀹㈡埛绔� return newFixedLengthResponse(data); -// return newFixedLengthResponse("success"); } catch (IOException e) { e.printStackTrace(); } catch (ResponseException e) { @@ -93,14 +92,38 @@ } //鍝嶅簲瀹㈡埛绔� return newFixedLengthResponse(data); -// return newFixedLengthResponse("success"); } - return newFixedLengthResponse("404"); } public static Response newFixedLengthResponse(String msg) { - return newFixedLengthResponse(Response.Status.OK, NanoHTTPD.MIME_HTML, msg); + + /** + 鏂囨湰绫诲瀷锛� + text/plain锛氱函鏂囨湰 + text/html锛欻TML 鏂囨。 + text/css锛欳SS 鏍峰紡琛� + text/javascript锛欽avaScript 鑴氭湰 + 搴旂敤绋嬪簭绫诲瀷锛� + application/json锛欽SON 鏁版嵁 + application/xml锛歑ML 鏁版嵁 + application/pdf锛歅DF 鏂囨。 + application/octet-stream锛氫簩杩涘埗鏁版嵁娴� + application/x-www-form-urlencoded锛歎RL 缂栫爜鐨勮〃鍗曟暟鎹� + application/zip锛歓IP 鍘嬬缉鏂囦欢 + application/x-gzip锛欸ZIP 鍘嬬缉鏂囦欢 + 鍥剧墖绫诲瀷锛� + image/jpeg锛欽PEG 鍥惧儚 + image/png锛歅NG 鍥惧儚 + image/gif锛欸IF 鍥惧儚 + image/svg+xml锛歋VG 鍥惧儚 + 闊抽/瑙嗛绫诲瀷锛� + audio/mpeg锛歁P3 闊抽 + video/mp4锛歁P4 瑙嗛 + video/mpeg锛歁PEG 瑙嗛 + */ +// NanoHTTPD.Response response=new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "application/zip",inputStream,inputStream.available()); + return newFixedLengthResponse(Response.Status.OK, "application/octet-stream", msg); } } -- Gitblit v1.8.0