Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 303应答时丢失标题_Java_Http_Http Headers_Http Status Code 303 - Fatal编程技术网

Java 303应答时丢失标题

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

我有以下处理程序,该处理程序将我的请求重定向到另一个处理程序(LoginHandler):

这是以下标题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用户。 我做错了什么


提前感谢。

响应头不遵循http重定向。您可以将其作为cookie或查询参数包含到
位置
标题中

将您的位置更改为:

hds.add("Location","/login?User=someUser");
或将其添加为SetCookie标头:

hds.add("Set-Cookie", "User=someuser")
Set Cookie将通知浏览器存储Cookie,并将其包含在返回服务器的所有请求中。虽然将其包含在您的位置中,但在处理重定向时将使其可访问一次

hds.add("Set-Cookie", "User=someuser")