Laravel GET方法未在服务器中发送原始JSON

问题描述 投票:0回答:1

使用Laravel中的REST API。无法使用GET方法在正文中发送原始json请求,它在我的服务器环境中返回了空值。但是在本地服务器上工作正常。请参考所附图像。我的控制器代码是

public function slots(Request $request)
{   //return $request->all();
    $consult_rule = TRUE;

    date_default_timezone_set('Asia/kolkata');
    $current_time = date('H:i:s');

    $curr_date = date('Y-m-d');

    // $appoint_date = DateTime::createFromFormat('d/m/Y', $request->appoint_date)->format('Y-m-d');

    // $appoint_date_format = strtotime($appoint_date);
    // $appoint_day = date('l', $appoint_date_format);

    $date = $request->appoint_date;

    $doctor_id = $request->doctor_id;

    $appoint_for = $request->appoint_for;



    return $this->sendResponse(['doctor_id' => $doctor_id,'appoint_date' => $date,'appoint_for' => $appoint_for], 'Data retrieved successfully.');
}

和图像,

对于本地服务器,效果很好Localhost response

对于服务器,使用关键参数可以正常工作Server response with key parameters

对于服务器,返回带有原始JSON参数的空值response with raw JSON parameters

laravel postman
1个回答
0
投票

由于它是GET路由,因此需要URL中的参数。对于POST请求,您需要定义一个单独的Route和函数,这些函数将在主体中接受参数。

编辑:使用GET HTTP方法时,您无法在正文中发送参数。

参考:https://laravel.com/docs/7.x/routing#required-parameters

© www.soinside.com 2019 - 2024. All rights reserved.