doufa5001 2015-06-11 08:24
浏览 75

带邮递员的PUT / PATCH请求在Laravel中返回状态码0

I have written some REST API Methods, including one for updating a DB entry:

// 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"

enter image description here

All the other methods work fine. Is the definition of my routing not correct?

Update When I send the data as x-www-form-urlencodedit works! When I send them as form-data it brings up the error message.

  • 写回答

2条回答 默认 最新

  • dongxia19772008 2016-12-13 08:14
    关注

    In Postman

    1. Change method to POST
    2. Add new variable _method with value PUT or PATCH
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本