【问题标题】:Laravel 5.4 : 500 Internal Server Error when accessing localhost APILaravel 5.4:访问 localhost API 时出现 500 内部服务器错误
【发布时间】:2017-10-16 04:26:35
【问题描述】:

我尝试使用 guzzle 在我的应用程序中调用 localhost API,但出现此错误:

ServerException in RequestException.php line 111:
Server error: `GET http://localhost/WingsFeedAPI/public/products` resulted 
in a `500 Internal Server Error` response:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow (truncated...)

https://github.com/ellipsesynergie/api-response 制作的API,当我访问http://localhost/WingsFeedAPI/public/products 时它返回:

// 20170517054157
// http://localhost/WingsFeedAPI/public/products

{
  "data": [
    {
      "id": 1,
      "nama_barang": "Daging ayam",
      "harga_barang": "5000",
      "rating": "123",
      "jenis_barang": "daging",
      "expired": "2017-05-03"
    }
  ]
}

这就是我在应用程序中调用该 API 的方式

控制器:

public function index()
{
    $client = new \GuzzleHttp\Client();
    $res = $client->request('GET','http://localhost/WingsFeedAPI/public/products');
    echo $res->getBody();
}

路线:

Route::get('/', 'WelcomeController@index');

【问题讨论】:

    标签: php api laravel-5 localhost guzzle


    【解决方案1】:

    我从here得到了解决方案;它需要以下步骤;

    第一个:从.env文件中删除下面的部分,

    DB_CONNECTION=mysql
    DB_HOST=
    DB_DATABASE=
    DB_USERNAME=
    DB_PASSWORD=
    

    第二个,在config/database.php文件中定义MySQL数据库参数。

    下面的 sn-p 突出显示了上面提到的数据库配置要编辑的部分;

    'mysql' => [
        'driver' => 'mysql',
        'host' => '',
        'database' => '',
        'username' => '',
        'password' => '',
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => false,
    ],
    

    【讨论】:

      【解决方案2】:

      Laravel 似乎工作正常。 请参阅 cmets 进行讨论。

      【讨论】:

      猜你喜欢
      • 2019-05-12
      • 1970-01-01
      • 2019-06-06
      • 2019-09-06
      • 2019-06-10
      • 1970-01-01
      • 2018-05-03
      • 2012-11-05
      • 2020-02-06
      相关资源
      最近更新 更多