From 31d32567ce92d2a3bc77865a6a1cec2635c9dc46 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期二, 28 十一月 2023 09:41:55 +0800 Subject: [PATCH] 2023年11月28日09:41:45 --- app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 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..9601d04 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; @@ -15,7 +17,7 @@ import fi.iki.elonen.NanoHTTPD; /** - * 鏈湴鏈嶅姟鍣� + * 鏈湴鏈嶅姟 */ public class MyNanoHttpServer extends NanoHTTPD { @@ -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,39 @@ } //鍝嶅簲瀹㈡埛绔� 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); +// return newFixedLengthResponse(Response.Status.OK, "application/zip", msg); } } -- Gitblit v1.8.0