0

我正在使用 NanoHTTPD 从 Android 本地托管网页。

我的问题是服务器响应我网站的索引页面,但我不知道如何导航到过去的任何页面,因为它总是会响应索引页面。

任何人都有任何教程,我正在努力寻找任何东西。谢谢 :)

private class MyHTTPD extends NanoHTTPD {
    public MyHTTPD() throws IOException {
        super(PORT, null);
    }

    @Override
    public Response serve(String uri, String method, Properties header, Properties parms, Properties files) {
        Log.d("response", "URI:" + uri + " method: " + method + " header: " + header + " parms: " + parms + " files: " + files);
        final StringBuilder buf = new StringBuilder();
        for (Entry<Object, Object> kv : header.entrySet())
            buf.append(kv.getKey() + " : " + kv.getValue() + "\n");
        handler.post(new Runnable() {
            @Override
            public void run() {
                hello.setText(buf);
            }
        });
         //load the index page
        String html = null;
        InputStream is = getClass().getResourceAsStream("/com/me/pages/index.html");
        byte[] b;
        try {
            b = new byte[is.available()];
            is.read(b);
            html = new String(b);
        } catch (IOException e) { // TODO Auto-generated catch block
            e.printStackTrace();
        }

                  //return index as response
        return new NanoHTTPD.Response(HTTP_OK, MIME_HTML, html);
    }
}
4

1 回答 1

0

NanoHTTPD not showing other pages

Of course, it won't show the others, as your petit serve function just serves the /com/me/pages/index.html file. For the other files (pages as you say), one needs to map the URI to the corresponding file to be served.

For examples, you could follow the development of the NanoHTTPD on github by different programmers. The network graph is here, and one particular fork which could be helpful to your case (serving multiple pages) is here.

于 2013-03-09T20:52:57.250 回答