0

When I visit http://129.0.1.23/ for the first time in a browser, the function DoSomething() will be launched and URL will be redirect to http://129.0.1.23/index.html?id=10&name=jack

When I visit http://129.0.1.23/ again, the function DoSomething() isn't be launched, and it seems that the browser has cached the URL http://129.0.1.23/, and the browser go to http://129.0.1.23/index.html?id=10&name=jack directly by cache.

How can I make a browser not cache URL? Thanks!

   @Override
   public Response serve(IHTTPSession session) {
      String uri = session.getUri();

      if (uri.endsWith("/")){
           String muri =uri+"index.html?id=10&name=jack";           
           DoSomething();
           return RedirectWebPage(muri);
      }

      return null;
   }




   private Response RedirectWebPage(String uri){
        Response res = newFixedLengthResponse(Response.Status.REDIRECT,
                NanoHTTPD.MIME_HTML,
                "<html><body>Redirected: <a href=\"" + uri + "\">" + uri + "</a></body></html>");
        res.addHeader("Location", uri);
        return res;
    }
HelloCW
  • 843
  • 22
  • 125
  • 310
  • You would do it using the same techniques as you would with any other Web server (e.g., `Cache-Control` headers). This has nothing specific to do with Android or NanoHTTPD. – CommonsWare Jul 03 '17 at 15:41
  • Thanks! could you show me some sample code about using cache-controls headers on NanoHTTPD? – HelloCW Jul 04 '17 at 00:03

0 Answers0