简体   繁体   English

该客户端请求使用哪种HTTP方法?

[英]Which HTTP method to use for this client request?

I am developing a REST web service in Java which on clients' request processes the request body and gives the output to the client. 我正在用Java开发REST Web服务,该服务应客户端的请求处理请求正文并将输出提供给客户端。 The request body sent by the client consists of a GO(programing language) program which the server executes(runs) on the server machine and returns the standard output of the program back to the client. 客户端发送的请求主体由GO(编程语言)程序组成,服务器在服务器计算机上执行(运行)该程序并将其的标准输出返回给客户端。 Now since the request body contains some text(program), I cannot use HTTP GET method to do that. 现在,由于请求主体包含一些文本(程序),因此我无法使用HTTP GET方法来做到这一点。 I can use PUT or POST, but I have learnt that they(PUT and POST) are generally used for updating/creating a resource. 我可以使用PUT或POST,但是我了解到它们(PUT和POST)通常用于更新/创建资源。 Since, I am not creating any resource here, is it conceptually correct to use PUT or POST. 因为我在这里没有创建任何资源,所以使用PUT或POST在概念上是否正确。 If not, which is the HTTP method that I need to use? 如果没有,我需要使用哪种HTTP方法?

Looking at the problem you are solving and comparing to an existing production solution , I suggest that you can use POST in your scenario. 查看正在解决的问题并将其与现有的生产解决方案进行比较,我建议您可以在方案中使用POST。

  • Reasoning - Example Production code solving similar problem:- 推理-解决类似问题的示例生产代码:-

Assuming that the problem you are trying to solve is this:- Clients submit code in Go programming language, Your server compiles it, runs it and then gives the output. 假设您要解决的问题是:-客户端以Go编程语言提交代码,您的服务器将其编译,运行并提供输出。 Assuming also that, it is somewhat similar to many online coding websites like hackerEarth, their API documentation page and the sample python code provided show that we can use HTTP:POST to submit code to the server for its processing. 还假设它与hackerEarth等许多在线编码网站有些相似,它们的API文档页面和提供的示例python代码表明,我们可以使用HTTP:POST将代码提交给服务器以进行处理。

POST is designed to allow a uniform method to cover the following functions: Providing a block of data, such as the result of submitting a form, to a data-handling process; POST旨在允许一种统一的方法来覆盖以下功能:向数据处理过程提供数据块(例如,提交表单的结果);

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. PUT方法请求将封闭的实体存储在提供的Request-URI下。 If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. 如果Request-URI引用了已经存在的资源,则应将封闭的实体视为驻留在原始服务器上的实体的修改版本。

  • Referring to the above statements, we can conclude that in the context of this problem which you are solving, you are requesting the server to do some data-handling for the enclosed entity, so you can use POST. 参考上面的陈述,我们可以得出结论,在您要解决的此问题的上下文中,您正在请求服务器对封闭的实体进行一些数据处理,因此可以使用POST。

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

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