I'm using NanoHTTPD to host a web page locally from Android.
My problem is that the server responds with the index page of my site but I can't figure out how to navigate to any pages past that because it will always respond with the index page.
Anybody got any tutorials, I'm struggling to find anything. Thanks :)
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);
}
}