我有以下处理程序,它将我的请求重定向到另一个处理程序(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();
}
}
}
这是下面的 Header,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();
}
}
我无法在 requestHeaders 上读取我添加的 Header USER。我究竟做错了什么?
提前致谢。