最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php使用GuzzleHttp實(shí)現(xiàn)HTTP請(qǐng)求

 更新時(shí)間:2023年11月06日 10:53:43   作者:bug改一年  
這篇文章主要為大家詳細(xì)介紹了php如何使用GuzzleHttp實(shí)現(xiàn)HTTP請(qǐng)求,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

1.composer安裝

composer require guzzlehttp/guzzle:~7.0

2.設(shè)置過(guò)期時(shí)間和跳過(guò)ssl驗(yàn)證

use GuzzleHttp\Client;
 
$client=new Client(['timeout' => 5, 'verify' => false]);

3.get請(qǐng)求

use GuzzleHttp\Client;
$client=new Client(['timeout' => 5, 'verify' => false]);
//設(shè)置headers頭
$headers=['Content-Type'=>"application/json"];
$url='https://api.netease.im/nimserver/history/queryMediaFileByChannelId.action';
$response=$client->get($url,[
                'headers'=>$headers,
            ]);
//獲取http響應(yīng)
$response->getStatusCode()
//獲取body找那個(gè)返回值信息
json_decode($response->getBody(),true);
//獲取響應(yīng)頭信息
 $response->getHeaders()

4.post請(qǐng)求 :json

use GuzzleHttp\Client;
$client=new Client(['timeout' => 5, 'verify' => false]);
//設(shè)置headers頭
$headers=['Content-Type'=>"application/json"];//json
$url='https://api.netease.im/nimserver/history/queryMediaFileByChannelId.action';
$body=[
                "namae"=>'zhou',
                "mode"=>2,
                "uid"=>1,
            ];
$response=$client->post($url,[
                'headers'=>$headers,
                'json'=>$body//發(fā)送body為josn格式
            ]);
//獲取http響應(yīng)
$response->getStatusCode()
//獲取body找那個(gè)返回值信息
json_decode($response->getBody(),true);
//獲取響應(yīng)頭信息
 $response->getHeaders()

5.post: content-type: application/x-www-form-urlencoded

use GuzzleHttp\Client;
$client=new Client(['timeout' => 5, 'verify' => false]);
//設(shè)置headers頭
$headers=['Content-Type'=>"application/x-www-form-urlencoded"];
$url='https://api.netease.im/nimserver/history/queryMediaFileByChannelId.action';
$body=[
                "namae"=>'zhou',
                "mode"=>2,
                "uid"=>1,
            ];
$response=$client->post($url,[
                'headers'=>$headers,
                'form_params'=>$body
            ]);
//獲取http響應(yīng)
$response->getStatusCode()
//獲取body找那個(gè)返回值信息
json_decode($response->getBody(),true);
//獲取響應(yīng)頭信息
 $response->getHeaders()

6.delete請(qǐng)求

use GuzzleHttp\Client;
 
$headers=['Content-Type'=>"application/json"];
$client=new Client(['timeout' => 5, 'verify' => false]);
$response=$client->delete($url,[
                'headers'=>$headers,
            ]);
            
$code=$response->getStatusCode();、

到此這篇關(guān)于php使用GuzzleHttp實(shí)現(xiàn)HTTP請(qǐng)求的文章就介紹到這了,更多相關(guān)php GuzzleHttp實(shí)現(xiàn)HTTP請(qǐng)求內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

华坪县| 闸北区| 治多县| 桦川县| 辽阳县| 嫩江县| 克东县| 尚义县| 三河市| 聂拉木县| 高台县| SHOW| 观塘区| 龙州县| 略阳县| 平安县| 两当县| 松桃| 南投县| 文安县| 从江县| 泰安市| 和林格尔县| 南江县| 山阴县| 象州县| 南康市| 天津市| 禹城市| 阿拉善右旗| 边坝县| 页游| 怀远县| 定兴县| 盐城市| 广安市| 于田县| 凤冈县| 宁陕县| 新闻| 德化县|