PHP Lumen - request body always empty

空扰寡人 提交于 2020-06-17 14:36:26

问题


I have started writing a small API in Lumen. When I send a request with Postman to my local project on XAMPP, I always get the correct response and all request body data is set. But now that I'm trying to make a request to my project on live hosting, the request body is always completely empty. I'm therefore assuming something in PHP hosting settings is not set correctly, but can't figure out what. Any tips on what to check / look out for would be appreciated. No error is reported on live hosting.

PHP version on hosting: 7.4 Hosting has cPanel

Controller: ItemFetcher.php

<?php
namespace App\Http\Controllers;

use App\Item;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Laravel\Lumen\Routing\Controller;
use Mockery\Exception;

class ItemFetcher extends Controller
{
    public function getData(Request $request)
    {
        try {
            if (!$request->isJson())
                return response(500, 500);

            $checker = "...";
            $data = \GuzzleHttp\json_decode($request->getContent(), true);

            if (empty($data['checker'] || $data['checker'] != $checker) || empty($data['items']))
                return response(500, 500);

            $itemIDs = $data['items'];
            $returnData = array();

            foreach ($itemIDs as $id) {
                $queryData = (new \App\Item)->GetItemByNameID($id);
                array_push($returnData, $queryData);
            }

            return \GuzzleHttp\json_encode($returnData);
        }
        catch (\Exception $exception){
            return $exception;
        }
    }
}

Lumen routes

use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return App::version();
});

Route::get('/get_data', 'ItemFetcher@getData');

Get request in Postman I make

来源:https://stackoverflow.com/questions/62242867/php-lumen-request-body-always-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!