如何使用guzzlehttp使用此代码重写
我想在Laravel 5.8中使用HTTP立面,但我注意到此版本的Laravel不包括HTTP立面,因此我安装了GuzlehTTP。
但是现在我不知道如何使用此软件包重写此代码:
public function getAddress(Request $request)
{
$response=Http::timeout(15)->withHeaders([
'Api-Key' => 'api-key',
])->get('https://api.sitename.org/v4/reverse',[
"lat"=>$request->input('latitude'),
"lng"=>$request->input('longitude')
]);
$address=$response->json()['formatted_address'];
return view('address.index',compact('address'));
}
那么,如何使用guzzlehttp正确重写此代码以使用http
?
I wanted to use Http facade in Laravel 5.8 but I noticed that Http facade is not included in this version of Laravel so I installed GuzzleHttp.
But now I don't know how to rewrite this code with this package:
public function getAddress(Request $request)
{
$response=Http::timeout(15)->withHeaders([
'Api-Key' => 'api-key',
])->get('https://api.sitename.org/v4/reverse',[
"lat"=>$request->input('latitude'),
"lng"=>$request->input('longitude')
]);
$address=$response->json()['formatted_address'];
return view('address.index',compact('address'));
}
So how can I properly rewrite this code using GuzzleHttp in order to use the Http
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于Guzzle遵循PSR-7(我认为)没有内置的方法来解码其他响应或对您显而易见
Since guzzle follows psr-7 (I think) there is no builtin method to decode response other things or obvious to you I guess