PUT 请求未在 Laravel 5.3 中找到正文数据
No body data found in Laravel 5.3 with PUT request
这是我更新联系人的路径。
Route::put( 'contact-type/{id}', 'ContactTypeController@update' );
这是用于测试请求是否与 PUT 请求一起存在的控制器。
public function update(Request $request, $id)
{
return response()->json([ 'id' => $id, 'req' => $request->all() ]);
}
当我使用邮递员发送请求时,请求为空!
laravel PUT 请求中是否不允许主体负载?或者我们如何在 PUT 请求中发送额外的数据?
只需从 form-data
更改为 x-www-form-urlencoded
:
您需要为您的数据添加适当的 Content-Type
header。
单击 x-www-form-control
这应该添加适当的 header。
希望对您有所帮助!
您传递的是表单数据,您需要在 post-man 中检查 x-www-form-urlencoded。
如果您必须使用 form-data(上传图片),因为 x-www- 中不存在文件输入表单 urlencode
您可以发送 POST-请求并添加一个字段,名称为 _method,值为 PUT 或 PATCH到请求正文。
这是我更新联系人的路径。
Route::put( 'contact-type/{id}', 'ContactTypeController@update' );
这是用于测试请求是否与 PUT 请求一起存在的控制器。
public function update(Request $request, $id)
{
return response()->json([ 'id' => $id, 'req' => $request->all() ]);
}
当我使用邮递员发送请求时,请求为空!
laravel PUT 请求中是否不允许主体负载?或者我们如何在 PUT 请求中发送额外的数据?
只需从 form-data
更改为 x-www-form-urlencoded
:
您需要为您的数据添加适当的 Content-Type
header。
单击 x-www-form-control
这应该添加适当的 header。
希望对您有所帮助!
您传递的是表单数据,您需要在 post-man 中检查 x-www-form-urlencoded。
您可以发送 POST-请求并添加一个字段,名称为 _method,值为 PUT 或 PATCH到请求正文。