繁体   English   中英

在Google Cloud Endpoints中获取原始HTTP数据(标题,Cookie等)

[英]Getting raw HTTP Data (Headers, Cookies, etc) in Google Cloud Endpoints

我想知道是否有可能在Cloud Endpoint中收集原始HTTP数据。 我似乎无法在Google的文档中找到任何内容,但App Engine的Twitter告诉我它是( https://twitter.com/app_engine/status/305747445017624576 )。 如果是这样,我可以请它的语法吗? 我知道GCE的API仍处于早期阶段,任何帮助都将不胜感激。

将HttpServletRequest参数添加到您的端点方法,例如

@ApiMethod
public MyResponse getResponse( HttpServletRequest req, @Named("infoId") String infoId ) {
    // Use 'req' as you would in a servlet, e.g.
    String ipAddress = req.getRemoteAddr();
    ...
}

该请求在Endpoints方法中可用作注入类型 当您在具有该类型的方法上声明参数时,将无形中将HttpServletRequest类型的对象注入到Java方法定义中,如下所示:

import javax.servlet.http.HttpServletRequest;
...

@ApiMethod
public MyMethod getRequest( HttpServletRequest req ) {

HttpServletRequest myRequest = req;
...
}

这在此处记录:

https://cloud.google.com/endpoints/docs/frameworks/java/parameter-and-return-types#injected_types

引自上述文件:

注入类型

注入类型是由Cloud Endpoints Frameworks接受特殊处理的类型。 如果将此类型用作方法参数,则不会将其作为API的一部分。 相反,该参数由Endpoints Frameworks填充。

注入的类型如下:

com.google.appengine.api.users.User

javax.servlet.http.HttpServletRequest

javax.servlet.ServletContext

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM