• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 HTTP Client Requests in XF2?

Jaxel

Well-known member
#1
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:

Jaxel

Well-known member
#2
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();