Swoft 踩坑筆記七 - 傳送請求
阿新 • • 發佈:2018-11-29
$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();