1. 程式人生 > >Swoft 踩坑筆記七 - 傳送請求

Swoft 踩坑筆記七 - 傳送請求

$client = new Client();
$response = $client->get($url)->getResponse();

返回的是一個物件
在這裡插入圖片描述

$client = new Client();
$response = $client->get($url)->getResult();

返回的是上面物件裡倒數第五行的contents,是一個字串型別。

其它請求型別

use Swoft\HttpClient\Client;

$client = new Client();
$response = $client->get('http://www.swoft.org')->getResponse();
$response = $client->post('http://www.swoft.org')->getResponse();
$response = $client->head('http://www.swoft.org')->getResponse();
$response = $client->options('http://www.swoft.org')->getResponse();
$response = $client->patch('http://www.swoft.org')->getResponse();
$response = $client->put('http://www.swoft.org')->getResponse();
$response = $client->delete('http://www.swoft.org')->getResponse();