Khetha i-CurlTransport ngaphambi kokudlulisela izinketho ze-CURLOPT eziyizinombolo. I-HTTP client ye-Yii2 isebenzisa i-StreamTransport ngokuzenzakalela futhi ayiphenduki i-cURL ngenxa nje yokuthi lezi zingaguquki zikhona:

$client = new \yii\httpclient\Client([
    'transport' => \yii\httpclient\CurlTransport::class,
]);

$response = $client->createRequest()
    ->setMethod('GET')
    ->setUrl('https://api.example/items')
    ->setOptions([
        CURLOPT_PROXY => 'http://proxy.example:8080',
        CURLOPT_PROXYAUTH => CURLAUTH_BASIC,
        CURLOPT_PROXYUSERNAME => $proxyUser,
        CURLOPT_PROXYPASSWORD => $proxyPassword,
        CURLOPT_CONNECTTIMEOUT => 5,
        CURLOPT_TIMEOUT => 15,
    ])
    ->send();

Sebenzisa indawo yokusebenza ye-PHP enesandiso se-cURL. Lesi sibonelo silindele i-proxy ye-HTTP eyamukela i-Basic; hlanganisa i-proxy nendlela esekelwa yi-transport.

CURLOPT_PROXYAUTH ikhetha ukuqinisekisa kumxhumanisi. CURLOPT_HTTPAUTH nemvume ye-API zisebenzela indawo okuyiwa kuyo.

Izinketho zesicelo ezabiwe ze-Yii2, kuhlanganisa i-proxy ebona ushintsho lwezinhlamvu ezinkulu nezincane kanye nezikhathi zokulinda, zingenye i-interface. Aziwenzi ama-constant e-cURL angenasizathu adluliseka phakathi kwama-backend.

Uma i-Client.requestConfig inikela ngamavelu azimisiwe okufanele ahlale, sebenzisa i-addOptions ukuze wengeze ngesicelo ngasinye. I-setOptions ekhonjisiwe ithatha indawo yaleyo qoqo futhi ingasusa izinketho ezizuzwe njengefa.

Izihloko ezihlobene