PATCH 和 PUT 请求不适用于表单数据

新手上路,请多包涵

我正在使用 Laravel 创建一个 RESTFUL 应用程序,并使用 Postman 测试该应用程序。目前,如果从 Postman 发送的数据带有表单数据,则 PATCHPUT 存在问题。

 // 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 for PATCH , PUT , and POST .
  • 但是,如果我使用 Postman 的表单数据发送 PUTPATCH ,则 $request->all() 将为空(参数不会发送到后端)。

现在的解决方案是使用 POST 来更新模型。我想知道为什么 PATCHPUT 在使用 Postman 的表单数据发送时不起作用。

原文由 notalentgeek 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 275
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题