php 用guzzule 6 發送HTTP請求

guzzle不知不覺升級到六,升級以後和原來3.*的時候用法不一樣了,看文檔也迷糊,找了半天才從文檔找到用法:
POST

$response = $client->request('POST', 'http://httpbin.org/post', [
    'form_params' => [
        'field_name' => 'abc',
        'other_field' => '123',
        'nested_field' => [
            'nested' => 'hello'
        ]
    ]
]);
$result = $response->getBody();

GET

$client = new Client();
$res = $client->request('GET', $url . "?param1=1&param2=9");
$result = $res->getBody();

講道理,還是挺方便的。

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