Gutzzle的常見使用

1.發起請求  

$client = new Client;
$url = "http://192.168.1.207/icar_dev101/miniapp.php/sstore/hot_goods_list/";
//get通過普通參數獲取
$response = $client->get($url,['query' => ['sstore_id' => 1]]);

//post提交普通參數
$response = $client->post($url,['form_params'=>['id'=>2]]);

//post提交文件
$response = $client->post($url,['multipart'=>[
    		[
            'name'     => 'qux',//字段鍵名
            'contents' => fopen('/path/to/file', 'r'),//文件句柄
            'filename' => 'custom_filename.txt' //文件名
        	]
        ]]);

//put提交json
$response = $client->put($url, ['json' => ['foo' => 'bar']]);

 

發佈了78 篇原創文章 · 獲贊 25 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章