【发布时间】: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