[英]Laravel 5.4 : 500 Internal Server Error when accessing localhost API
我試圖使用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');
我從這里得到了解決方案; 它需要以下步驟;
第一個:從.env
文件中刪除下面的.env
,
DB_CONNECTION=mysql
DB_HOST=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
第二個,在config/database.php
文件中定義MySQL數據庫參數。
下面的代碼段突出顯示了上面提到的數據庫配置要編輯的部分;
'mysql' => [
'driver' => 'mysql',
'host' => '',
'database' => '',
'username' => '',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Laravel似乎工作正常。 請參閱評論以供討論。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.