邮递员的 PUT/PATCH 请求在 Laravel 中返回状态代码 0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30775428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PUT/PATCH request with postman returns status code 0 in Laravel
提问by sesc360
I have written some REST API Methods, including one for updating a DB entry:
我编写了一些 REST API 方法,包括用于更新数据库条目的方法:
// Update
public function update(CreateAEDRequest $request, $id) {
$aed = AED::find($id);
if(!$aed) {
return response()->json(['message' => "Dieser AED exisitiert nicht", 'code' => 404], 404);
}
$owner = $request->get('owner');
$street = $request->get('street');
$aed->owner = $owner;
$street->street = $street;
$aed->save();
return response()->json(['message' => 'Der AED wurde aktualisiert'], 200);
}
The Route is defined as:
路由定义为:
Route::put('/aeds/{aeds}', 'APIAEDController@update');
Route::patch('/aeds/{aeds}', 'APIAEDController@update');
A Request is being handled by:
请求正在由以下人员处理:
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
use Illuminate\Http\JsonResponse;
class CreateAEDRequest extends Request
{
public function authorize()
{
// turn back to false when doing auth
return true;
}
public function rules()
{
return [
'owner' => 'required',
'street' => 'required'
];
}
}
But when I use postman and try to update the existing DB entry and I fill in the owner and street variable to be sent in POSTMAN as requested, I get the message: "Could not get any response. Returns Status Code 0"
但是,当我使用邮递员并尝试更新现有的数据库条目并按照要求填写要在邮递员中发送的所有者和街道变量时,我收到消息:“无法获得任何响应。返回状态代码 0”
All the other methods work fine. Is the definition of my routing not correct?
所有其他方法都可以正常工作。我的路由定义不正确吗?
UpdateWhen I send the data as x-www-form-urlencoded
it works! When I send them as form-data it brings up the error message.
更新当我发送数据x-www-form-urlencoded
时!当我将它们作为表单数据发送时,它会显示错误消息。
回答by Oleg Abrazhaev
回答by Kate S.
In Postman
在 Postman
- Change method to
POST
- Add new variable
_method
with valuePUT
orPATCH
- 将方法更改为
POST
- 添加
_method
具有值PUT
或的新变量PATCH