Java 303应答时丢失标题
我有以下处理程序,该处理程序将我的请求重定向到另一个处理程序(LoginHandler): 这是以下标题LoginHeader:Java 303应答时丢失标题,java,http,http-headers,http-status-code-303,Java,Http,Http Headers,Http Status Code 303,我有以下处理程序,该处理程序将我的请求重定向到另一个处理程序(LoginHandler): 这是以下标题LoginHeader: public class LoginHandler implements HttpHandler { @Override public void handle(HttpExchange httpExchange) throws IOException { //I can't read the header USER on the f
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用户。
我做错了什么
提前感谢。响应头不遵循http重定向。您可以将其作为cookie或查询参数包含到
位置
标题中
将您的位置更改为:
hds.add("Location","/login?User=someUser");
或将其添加为SetCookie标头:
hds.add("Set-Cookie", "User=someuser")
Set Cookie将通知浏览器存储Cookie,并将其包含在返回服务器的所有请求中。虽然将其包含在您的位置中,但在处理重定向时将使其可访问一次
hds.add("Set-Cookie", "User=someuser")