如何访问HTTP请求? [英] How do I access the HTTP request?

查看:97
本文介绍了如何访问HTTP请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说通常我在Java中有一个rest方法

Say normally I have a rest method in java

@POST 
    @Path("/test")
    @Produces(MediaType.APPLICATION_JSON)
    public String showTime(@FormParam("username") String userName) {

:
:
:
}

这很好,但是我想知道是否有一种方法可以使用jersey等访问完整的HTTP请求

which is fine, however I'm wondering is there a way I can access the full HTTP request with jersey such as

@POST 
    @Path("/test")
    @Produces(MediaType.APPLICATION_JSON)
    public String showTime(@FormParam("username") String userName,@XXXXXX String httpRequest) {

:
:
:
}

其中一些注释会给我完整的HTTP请求以存储在变量中.曾尝试使用@POST,但似乎无法正常工作.有任何建议.

where some annotation would give me the full HTTP request to store in a variable. Have tried using @POST but it doesnt seem to work. Any suggestions.

谢谢

推荐答案

您可以使用@Context批注:

You can use the @Context annotation:

@POST 
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public String showTime(
    @FormParam("username") String userName,
    @Context HttpServletRequest httpRequest
) {
    // The method body
}

这篇关于如何访问HTTP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆