根据HTTP/1.1规范:
该
POST方法用来请求原始服务器接受被附在请求由标识的资源的新下属实体Request-URI的Request-Line
换句话说,POST用于创建.
该
PUT方法请求将所包含的实体存储在提供的实体下Request-URI.如果Request-URI引用已经存在的资源,则封闭的实体应该被视为驻留在源服务器上的实体的修改版本.如果Request-URI未指向现有资源,并且该URI能够被请求用户代理定义为新资源,则源服务器可以使用该URI创建资源.
也就是说,PUT用于创建或更新.
那么,应该使用哪一个来创建资源?或者需要支持两者?
我PUT在我的Rails应用程序中使用了一个请求.现在,PATCH浏览器已经实现了一个新的HTTP动词.所以,我想知道PATCH和PUT请求之间的主要区别是什么,以及什么时候应该使用其中一个.
如何使用Fiddler检查来自Web服务器的响应.我可以通过将URL粘贴到Request Builder中的字段来轻松检查GET方法,并在xml/json中返回响应.有一个选项POST,但我不知道如何将参数传递给POST.
例如:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.google.com/accounts/ClientLogin");
request.Method = "POST";
string postData = "accountType=HOSTED_OR_GOOGLE";
postData += "&Email=yourusername@gmail.com";
postData += "&Passwd=yourpassword";
postData += "&service=finance";
postData += "&source=test-test-.01";
Run Code Online (Sandbox Code Playgroud)
如何在Fiddler中将我的数据传递给此POST方法以获取响应?
new_story GET /story/new(.:format) {:action=>"new", :controller=>"stories"}
edit_story GET /story/edit(.:format) {:action=>"edit", :controller=>"stories"}
story GET /story(.:format) {:action=>"show", :controller=>"stories"}
PUT /story(.:format) {:action=>"update", :controller=>"stories"}
DELETE /story(.:format) {:action=>"destroy", :controller=>"stories"}
POST /story(.:format) {:action=>"create", :controller=>"stories"}
Run Code Online (Sandbox Code Playgroud)
在网络工作中,我已经完成了其他技术,我只使用过GET和POST方法.但是在Rails中使用RESTful路由时,默认情况下,PUT和DELETE方法用于更新和销毁操作.使用PUT和DELETE的优点或需求是什么?我假设这些方法只是做POST的另一种方式 - 但为什么不坚持使用POST?
我正在写一个网络服务.任何人都可以解释一下这些方法并给我一些关于它们的例子吗?谢谢您帮忙.
我正在使用Android的Retrofit。通过基于REST的Web服务很容易检索和上传JSON。我们可以在Flutter中获得与Web服务的Retrofit等效的任何库吗?
阅读此 SO链接后,
PUT 最常用于更新功能,PUT 到已知资源 URI,请求正文包含原始资源的最新更新表示。
...我们需要再次发送数据的所有参数。
在我的控制器中,我有:
$student = Student::find($student_id);
$student->username = $request->username;
$student->email = $request->email;
$student->password = $request->password;
$path = $request->file('passport')->store('upload');
$student->passport = $path;
Run Code Online (Sandbox Code Playgroud)
我曾经对POST方法使用过相同的代码并且它有效,但是在将它用于 API 时,我使用了 POSTMANform-data并且必须$request->all()是null. 有人说我应该使用,x-www-form-urlencoded但这不允许文件上传。
我收到带有 OPTIONS 方法的 204,但似乎没有达到终点

只需构建一个简单的文件上传端点,如下所示:
package main
import (
"cloud.google.com/go/storage"
"github.com/gin-gonic/gin"
"github.com/gin-contrib/cors"
"google.golang.org/api/option"
"io"
"log"
)
const uploadBucket = "some-cool-bucket-name"
const uploadApiKey = "some-advanced-key"
func main() {
router := gin.Default()
rg := router.Group("api/v1/photo")
{
rg.PATCH("/", uploadFile)
}
router.Use(cors.Default())
router.Run()
}
func uploadFile(c *gin.Context) {
mr, e := c.Request.MultipartReader()
if e != nil {
panic("Error reading request")
}
client, e := storage.NewClient(c, option.WithAPIKey(uploadApiKey))
bucket := client.Bucket(uploadBucket)
for {
p, e := mr.NextPart()
if e == io.EOF {
break
} else if …Run Code Online (Sandbox Code Playgroud)