Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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 从MessageContext.HTTP\u响应\u头获取Cookie值_Java_Cookies_Http Headers - Fatal编程技术网

Java 从MessageContext.HTTP\u响应\u头获取Cookie值

Java 从MessageContext.HTTP\u响应\u头获取Cookie值,java,cookies,http-headers,Java,Cookies,Http Headers,如何从cookie列表中获取特定cookie的值。下面是我如何尝试的: Map<String, List<String>> map = (Map<String, List<String>>) context.get(MessageContext.HTTP_RESPONSE_HEADERS); List<String> contentType = getHTTPHeade

如何从cookie列表中获取特定cookie的值。下面是我如何尝试的:

        Map<String, List<String>> map = (Map<String, 
                List<String>>) context.get(MessageContext.HTTP_RESPONSE_HEADERS);

        List<String> contentType = getHTTPHeader(map);
        if (contentType != null) {
            StringBuffer strBuf = new StringBuffer();
            for (String type : contentType) {
                strBuf.append(type);
            }
            System.out.println("Content-Type:" + strBuf.toString());
        }

        List<String> cookies = map.get("Set-Cookie"); 
        if (cookies != null) {
            System.out.println("cookies != null");
            StringBuffer strBuf = new StringBuffer();
            for (String type : cookies) {
                System.out.println(" Looping cookie ");
                strBuf.append(type);
            }
            System.out.println("Cookie:" + strBuf.toString());
        }else{
            System.out.println("cookies == null");
        }
谢谢。

cookie.substring(cookie.indexOf(“:”),cookie.indexOf(“;”).split(“=”)[1]

或者如果你想要正则表达式

Pattern p = Pattern.compile( "JSESSIONID=([A-Z0-9]+)");
Matcher m = p.matcher(cookie);
m.find();
m.group(1);

你不能从会话本身获取会话id吗?你是什么意思?它已被设置为cookie的一部分,我必须在下一个请求中阅读并传递它。如果您提出请求,像httpclient这样的客户端可以自动为您处理这些cookie。
Pattern p = Pattern.compile( "JSESSIONID=([A-Z0-9]+)");
Matcher m = p.matcher(cookie);
m.find();
m.group(1);