How to create nanohttpd server in android?

后端 未结 4 1503
情话喂你
情话喂你 2021-02-09 05:10

Actually ,I had searched some questions and go to the github. But I\'m new ,I cannot understand the example.

I want to create the http server in android so I can access

4条回答
  •  北海茫月
    2021-02-09 05:43

    This is the code working for me, but I have different version of NANOHTTPD, I don't have time right now to test out your solution. Here is UploadServer class and Nano class. I return file-upload.htm from sdcard/Discover Control/Web path

    public class UploadServer extends NanoHTTPD {
    public UploadServer() throws IOException {
        super(8080, new File("."));
    }
    
    public Response serve( String uri, String method, Properties header, Properties parms, Properties files ) {
        File rootsd = Environment.getExternalStorageDirectory();
        File path = new File(rootsd.getAbsolutePath() + "/Discover Control/Web");
        Response r = super.serveFile("/file-upload.htm", header, path, true);
        return r;
    }
    }
    

    NanoHttpd class

    NanoHTTPD.java

    FILE UPLOAD

    file-upload.htm

    Hope this helps and enjoy your work.

提交回复
热议问题