0

次のハンドラーがあり、リクエストを別のハンドラー (LoginHandler) にリダイレクトします。

public class ValidationHandler implements HttpHandler
{
    @Override
    public void handle(HttpExchange httpExchange) throws IOException
    {
       // Serve for POST requests only
       if (httpExchange.getRequestMethod().equalsIgnoreCase("POST"))
       {  
           Headers hds = httpExchange.getResponseHeaders();
           hds.add("Content-type","text/html");
           hds.add("Location","/login");
           //WHERE I ADD THE USER
           hds.add("User", "someUser");
           //SEND A 303 to go to another handler (LoginHandler)
           httpExchange.sendResponseHeaders(303,0);  
           httpExchange.close();
       }
   }
}

これは、次のヘッダー、LoginHeader です。

public class LoginHandler implements HttpHandler
{

   @Override
   public void handle(HttpExchange httpExchange) throws IOException
   {
        //I can't read the header USER on the following line!
       httpExchange.getRequestHeaders().forEach((k,v) -> System.out.println(k + ':' + v));

        httpExchange.sendResponseHeaders(200,data.length());
        httpExchange.getResponseBody().write(data.getBytes());
        httpExchange.close();
   }
}

追加したヘッダー USER を requestHeaders で読み取ることができません。私は何を間違っていますか?

前もって感謝します。

4

1 に答える 1