yii\httpclient\Client provides several different ways to actually send an HTTP message - several transports. Predefined transports are:
You may configure the transport to be used by particular client using yii\httpclient\Client::$transport:
use yii\httpclient\Client;
$client = new Client([
'transport' => 'yii\httpclient\CurlTransport'
]);
You may create your own transport, which will perform message sending in its own way. To do so you should
extend yii\httpclient\Transport class and implement at least send()
method. All you need to do is
determine HTTP response content and headers, then you can compose a response object from them using
yii\httpclient\Client::createResponse():
use yii\httpclient\Transport;
class MyTransport extends Transport
{
/**
* @inheritdoc
*/
public function send($request)
{
$responseContent = '???';
$responseHeaders = ['???'];
return $request->client->createResponse($responseContent, $responseHeaders);
}
}
You may as well override batchSend()
method if there is a way to send multiple requests with better performance
like sending them asynchronously in parallel.