【发布时间】:2018-06-05 04:15:05
【问题描述】:
我正在使用 Laravel 创建一个 RESTFUL 应用程序,并使用 Postman 测试该应用程序。目前,PATCH 或 PUT 如果从 Postman 发送的数据带有 form-data,则会出现问题。
// 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。 - 使用 x-www-form-urlencoded、
$request->all()可以用于PATCH、PUT和POST。 - 但是,如果我从 Postman 发送带有表单数据的
PUT和PATCH,则$request->all()将为空(参数不会发送到后端)。
目前的解决方案是使用POST 更新模型。我想知道为什么 PATCH 和 PUT 在使用 Postman 的表单数据发送时不起作用。
【问题讨论】:
-
我不认为它涵盖了为什么表单数据不适用于
PATCH和PUT请求。 -
我看到了,到现在还没有解决方案。
-
你一定没看清楚,请看我的回答。