laravel guzzle 发起请求

1、安装guzzle

composer require guzzlehttp/guzzle

2、引入

use GuzzleHttpClient;

3、发起请求

        //发起Http请求  并设置超时时间
        $client = new Client(['timeout'=>5]);
        //得到URL地址
        $url=config('gaode.geocode');
        //替换占位符$url=sprintf($url,$model->fang_addr,$city->name);
        //发起请求
        $response=$client->get($url);
        //可尝试 打印$response看看
        $body=(string)$response->getBody();
//格式化
$arr=json_decode($body,true);
     /*
      * 对数据进行处理
     */      
原文地址:https://www.cnblogs.com/zqblog1314/p/12774546.html