XF 2.0 HTTP Client Requests in XF2?

Jaxel

Well-known member
How do you do http requests in XF2?

This was my code in XF1:
Code:
    $client = new Zend_Http_Client('https://api.twitch.tv/kraken/streams');
    $client->setHeaders('Accept', 'application/vnd.twitchtv.v5+json');
    $client->setHeaders('Client-ID', $service['service_apikey']);
    $client->setParameterGet(array(
        'channel' => $channelsList,
        'limit' => 100,
    ));

    try
    {
        $feed = $client->request()->getBody();
        $json = json_decode($feed, true);
    }
 
Last edited:
I figured it out.

Code:
            $client = \XF::app()->http()->client();
            $response = $client->get('https://api.twitch.tv/kraken/streams', [
                'headers' => [
                    'Accept' => 'application/vnd.twitchtv.v5+json',
                    'Client-ID' => $service->service_apikey,
                ],
                'query' => [
                    'channel' => $channelsList,
                    'limit' => $limit,
                ],
            ]);
            $json = $response->json();
 
Back
Top Bottom