有没有一种方法可以使用GET请求获取请求正文? [英] Is there a way to get the request body with GET request?

查看:98
本文介绍了有没有一种方法可以使用GET请求获取请求正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个api:

@Path("test")
@GET
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public Parameter performTest(Parameter in) {
    System.out.println(in);
}

,但是in始终返回null.我可以将@GET更改为@POST,并且可以使用,但是我并没有真正执行创建或更新操作,因此使用post似乎很奇怪.

but the in always returns null. I can change @GET to @POST and it works but I'm not really performing an create or update so using post seems odd.

有没有办法通过球衣获得GET请求来获取尸体?

Is there a way to get the body with a GET request with jersey?

推荐答案

TL; DR 正确的解决方案是使用POST.

TL;DR The correct solution is to use POST.

我可以将@GET更改为@POST,并且可以,但是我并没有真正执行创建或更新操作,因此使用post似乎很奇怪"

"I can change @GET to @POST and it works but I'm not really performing an create or update so using post seems odd"

为什么这么奇怪? POST不仅限于创建/更新操作.

Why is that odd? POST is not limited to create/update operations.

规范( RFC 7231,第4.3.3.节 >)说:

POST方法根据资源自身的特定语义,请求目标资源处理包含在请求中的表示形式.例如,POST用于以下功能(以及其他功能):

The POST method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics. For example, POST is used for the following functions (among others):

  • 为数据处理过程提供一块数据,例如以HTML形式输入的字段;

  • Providing a block of data, such as the fields entered into an HTML form, to a data-handling process;

在公告板上,新闻组,邮件列表,博客或类似的文章组中发布消息;

Posting a message to a bulletin board, newsgroup, mailing list, blog, or similar group of articles;

创建尚未由原始服务器识别的新资源;和

Creating a new resource that has yet to be identified by the origin server; and

将数据追加到资源的现有表示形式.

Appending data to a resource's existing representation(s).

换句话说,POST的意思是这里有一些数据,请为我处理".

To paraphrase, POST means "here's some data, please process it for me".

当然,处理"在创建/更新中通常表示存储",但这并不是处理数据的唯一方法.

Sure, "process" often means "store", as in create/update, but that is not the only way to process data.

在您的情况下,处理"表示使用这些参数运行测试".

In your case, "process" means "run test, using these parameters".

这篇关于有没有一种方法可以使用GET请求获取请求正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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