[英]Laravel 5.4 : 500 Internal Server Error when accessing localhost API
i tried to call localhost API in my application using guzzle, but i got this error: 我试图使用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...)
the API made with https://github.com/ellipsesynergie/api-response , and when i access http://localhost/WingsFeedAPI/public/products it returns : 使用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"
}
]
}
And this is how i call that API in my application 这就是我在我的应用程序中调用该API的方式
Controller : 控制器:
public function index()
{
$client = new \GuzzleHttp\Client();
$res = $client->request('GET','http://localhost/WingsFeedAPI/public/products');
echo $res->getBody();
}
Route : 路线:
Route::get('/', 'WelcomeController@index');
I got the solution from here ; 我从这里得到了解决方案; it requires the following steps;
它需要以下步骤;
The first one: to remove section below from the .env
file, 第一个:从
.env
文件中删除下面的.env
,
DB_CONNECTION=mysql
DB_HOST=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
The second one, to define in the config/database.php
file the MySQL database parameters. 第二个,在
config/database.php
文件中定义MySQL数据库参数。
The snippet below highlights the portion to be edited for the database configuration a referred right above; 下面的代码段突出显示了上面提到的数据库配置要编辑的部分;
'mysql' => [
'driver' => 'mysql',
'host' => '',
'database' => '',
'username' => '',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Laravel appears to be working fine. Laravel似乎工作正常。 See comments for discussion.
请参阅评论以供讨论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.