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

php使用GuzzleHttp實現(xiàn)HTTP請求

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

1.composer安裝

composer require guzzlehttp/guzzle:~7.0

2.設(shè)置過期時間和跳過ssl驗證

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

3.get請求

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找那個返回值信息
json_decode($response->getBody(),true);
//獲取響應(yīng)頭信息
 $response->getHeaders()

4.post請求 :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找那個返回值信息
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找那個返回值信息
json_decode($response->getBody(),true);
//獲取響應(yīng)頭信息
 $response->getHeaders()

6.delete請求

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實現(xiàn)HTTP請求的文章就介紹到這了,更多相關(guān)php GuzzleHttp實現(xiàn)HTTP請求內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

文登市| 习水县| 博乐市| 秭归县| 新宾| 汕尾市| 富顺县| 开江县| 德保县| 蓬溪县| 广安市| 遂平县| 扎兰屯市| 乌兰县| 乐安县| 虞城县| 交城县| 赤城县| 永宁县| 建始县| 米泉市| 上栗县| 深水埗区| 湟源县| 晋中市| 蒙山县| 乐陵市| 桂阳县| 台湾省| 阿尔山市| 搜索| 胶州市| 贵州省| 三亚市| 德钦县| 柞水县| 庆城县| 北川| 铜山县| 临西县| 鸡泽县|