且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有一种方法可以使用GET请求获取请求正文?

更新时间:2022-12-29 22:22:57

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".