我正在使用 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);
}
}