laravel guzzle 发起请求


1、安装guzzle

composer require guzzlehttp/guzzle

2、引入

use GuzzleHttp\Client;

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);
     /*
      * 对数据进行处理
     */      

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM