From d830fef6a2bc2ab061e6ac2b423c4a49dda3cf21 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期三, 06 十二月 2023 18:08:26 +0800 Subject: [PATCH] 2023年12月06日18:08:20 --- app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java | 36 +++++++++++++++++++++++++++++++----- 1 files changed, 31 insertions(+), 5 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 7d0b5f3..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 { @@ -74,7 +76,6 @@ } //鍝嶅簲瀹㈡埛绔� return newFixedLengthResponse(data); -// return newFixedLengthResponse("success"); } catch (IOException e) { e.printStackTrace(); } catch (ResponseException e) { @@ -91,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