有没有办法通过 GET 请求获取请求体?
Is there a way to get the request body with GET request?
我有这个api:
@Path("test")
@GET
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public Parameter performTest(Parameter in) {
System.out.println(in);
}
但始终 returns 为空。我可以将 @GET 更改为 @POST 并且它有效,但我并没有真正执行创建或更新,因此使用 post 似乎很奇怪。
有没有办法通过球衣的 GET 请求获取正文?
TL;DR 正确的解决方法是使用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 不限于 create/update 操作。
规范 (RFC 7231, section 4.3.3. 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):
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的意思是“这里有一些数据,请帮我处理一下”。
当然,“处理”通常表示“存储”,如 create/update 中所述,但这并不是处理数据的唯一方式。
在您的例子中,“过程”意味着“运行 测试,使用这些参数”。
我有这个api:
@Path("test")
@GET
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public Parameter performTest(Parameter in) {
System.out.println(in);
}
但始终 returns 为空。我可以将 @GET 更改为 @POST 并且它有效,但我并没有真正执行创建或更新,因此使用 post 似乎很奇怪。
有没有办法通过球衣的 GET 请求获取正文?
TL;DR 正确的解决方法是使用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 不限于 create/update 操作。
规范 (RFC 7231, section 4.3.3. 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):
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的意思是“这里有一些数据,请帮我处理一下”。
当然,“处理”通常表示“存储”,如 create/update 中所述,但这并不是处理数据的唯一方式。
在您的例子中,“过程”意味着“运行 测试,使用这些参数”。