D
D
Dromok2014-03-12 19:50:55
Zend Framework
Dromok, 2014-03-12 19:50:55

Zend Framework 2 - Why can't I set parameters for curl?

I'm trying to assign a useragent, but it doesn't work. The user agent remains the default "Zend\\Http\\Client". What is the problem?

$useragent = 'Mozilla/5.0';
        $adapter = new \Zend\Http\Client\Adapter\Curl();

        $client = new \Zend\Http\Client($url);
        $client->setAdapter($adapter);
        $client->setMethod('GET');
        $adapter->setOptions(array(
            'curloptions' => array(
                CURLOPT_USERAGENT => $useragent,
            )
        ));
        $respond = $client->send();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
devKP, 2016-03-12
@devKP

The useragent must be specified via the client option:

$client->setOptions([
    'useragent' => 'test',
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question