I'm trying to send data to Google Analytic's collector with Zend_Http_Client and POST. I have an array $postParams
that's including my tracking-ID, cid and hit types and I add the values of this array to my client via setParameterPost()
.
Here's the relevant part of my Action:
$client = new Zend_Http_Client('https://ssl.google-analytics.com/debug/collect');
foreach ($postParams as $postParam => $postValue) {
$client->setParameterPost($postParam, $postValue);
}
$response = $client->request();
When calling this script I get the following error:
Cannot handle content type '' automatically. Please use Zend_Http_Client::setRawData to send this kind of content.
It's thrown in the _prepareBody()
method in Zend_Http_Client. When I'm adding an echo($this->enctype); die();
there, I receive NULL
.
I'd add $client->setEncType();
to my code but the data is plain.
Has anyone an idea what I'm missing here? Do I really have to use setRawData
?
Thanks in advance!
Update: $client->setParameterPost('postParams', $postParams);
won't work too. It throws the same error.
This answer brought me back on track: https://stackoverflow.com/a/7407491/3218828
$rawData = '';
foreach ($postParams as $postParam => $postValue) {
if ($rawData !== '') {
$rawData .= '&';
}
$rawData .= $postParam . '%5B%5D=' . $postValue;
}
$client = new Zend_Http_Client();
$client->setRawData($rawData);
$client->setUri('https://ssl.google-analytics.com/debug/collect');
$client->request(Zend_Http_Client::GET);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With