我正在使用 Laravel 创建一个 RESTFUL 应用程序,并使用 Postman 测试该应用程序。目前,如果从 Postman 发送的数据带有表单数据,则 PATCH
或 PUT
存在问题。
// Parameter `{testimonial}` will be sent to backend.
Route::post ('testimonials/{testimonial}', 'TestimonialController@update');
// Parameter `{testimonial}` will not be sent to backend (`$request->all()` will be empty) if sent from Postman with form-data.
Route::patch ('testimonials/{testimonial}', 'TestimonialController@update');
Route::put ('testimonials/{testimonial}', 'TestimonialController@update');
- 使用表单数据,
$request->all()
可以用于POST
。 - Using x-www-form-urlencoded,
$request->all()
will be okay forPATCH
,PUT
, andPOST
. - 但是,如果我使用 Postman 的表单数据发送
PUT
和PATCH
,则$request->all()
将为空(参数不会发送到后端)。
现在的解决方案是使用 POST
来更新模型。我想知道为什么 PATCH
和 PUT
在使用 Postman 的表单数据发送时不起作用。
原文由 notalentgeek 发布,翻译遵循 CC BY-SA 4.0 许可协议
将此技巧添加到 Postman :
邮递员屏幕