【问题标题】:Laravel GET Method not sending raw JSON in ServerLaravel GET 方法不在服务器中发送原始 JSON
【发布时间】:2020-05-08 18:33:09
【问题描述】:

在 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】:

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

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

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

    【讨论】:

    • 但是在 localhost(xampp) 中它可以工作,在 GET 正文请求中带有参数,请解释一下它是如何工作的。
    • php 和 laravel 版本在 XAMPP 和服务器上是否相似?
    猜你喜欢
    • 2016-04-07
    • 2020-01-05
    • 2014-03-17
    • 2021-05-21
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    相关资源
    最近更新 更多