I'm trying to use Varien_Http_Client for calling external API, here's the code:
$httpClient = new Varien_Http_Client();
$httpClient->setUri('https://api-host/api/endpoint');
$httpClient->setMethod(Zend_Http_Client::GET)
$httpClient->setParameterGet([
'name' => 'John',
'gender' => 'male',
]);
$params = $httpClient->getUri()->getQuery();
The problem is $httpClient->getUri()->getQuery()
returns nothing if I set the GET parameters using setParameterGet()
like above, shouldn't it suppose to return name=John&gender=male
?
Updated: getQuery() after calling request, getting same result
$httpClient = new Varien_Http_Client();
$httpClient->setUri('https://api-host/api/endpoint');
$httpClient->setMethod(Zend_Http_Client::GET)
$httpClient->setParameterGet([
'name' => 'John',
'gender' => 'male',
]);
try {
$response = $httpClient->request();
Mage::log($httpClient->getUri()->getQuery());
} catch (Exception $e) {
Mage::log($e);
return $e;
}
One more thing, it works if I set the parameters this way
$httpClient->setUri('https://api-host/api/endpoint?name=John&gender=male');