AppEngine端点HTTP Cookie

时间:2013-09-07 10:48:25

标签: google-app-engine http cookies google-cloud-endpoints

我正在尝试从AppEngine端点方法中读出HTTP Cookie:

@ApiMethod(httpMethod = "get")
public void getAll(HttpServletRequest req) {

    log.info("req: " + req);

    Cookie[] cookies = req.getCookies();
    for (Cookie cookie : cookies) {
        log.info("cookie: " + cookie.getName() + " " + cookie.getValue());
    }


}

但无论我尝试什么,cookie都是NULL。有任何想法吗? 它应该以这种方式工作:http://chirashi.zenconsult.net/2013/07/custom-authentication-with-google-cloud-endpoints-using-app-engine-java

2 个答案:

答案 0 :(得分:2)

这样的事似乎对我有用。我已经在App Engine上测试了它。

@Api(name = "api_name", version = "v1", description = "An API", auth = @ApiAuth(allowCookieAuth = AnnotationBoolean.TRUE))

答案 1 :(得分:1)

它似乎不适用于Java。这里有一个错误: https://code.google.com/p/googleappengine/issues/detail?id=10100

使用Python,默认情况下不会传递Cookie,there is a way to enable them。我认为这个注释意味着在Java中做同样的事情,但似乎没有做任何事情:

@ApiAuth(allowCookieAuth = AnnotationBoolean.TRUE)