我正在使用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);
}
}发布于 2013-03-09 20:52:57
NanoHTTPD没有显示其他页面
当然,它不会显示其他函数,因为您的小serve函数只是服务于/com/me/pages/index.html文件。对于其他文件(如您所说的页面),需要将URI映射到要服务的相应文件。
例如,您可以跟踪不同程序员在github上开发NanoHTTPD的过程。网络图就在这里,一个可能对您的情况有帮助的分叉(为多个页面服务)是这里。
https://stackoverflow.com/questions/15315367
复制相似问题