Content Type Error When Using Zend_Http_Client

I am trying to send data to a Google Analytics collector using Zend_Http_Client and POST. I have an array of $postParams that includes my tracking identifiers, cid and hit and add the values โ€‹โ€‹of this array to my client using setParameterPost() .

Here is 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, the following error appears:

Unable to process content type '' automatically. To send such content, use Zend_Http_Client :: setRawData.

It has been added to the _prepareBody() method in Zend_Http_Client. When I add echo($this->enctype); die(); echo($this->enctype); die(); I get NULL .

I would add $client->setEncType(); to my code, but the data is simple.
Does anyone know what I'm missing here? Do I really have to use setRawData ?

Thanks in advance!

Update: $client->setParameterPost('postParams', $postParams); will not work either. It gives the same error.

+6
source share
1 answer

This answer got me back on track: fooobar.com/questions/986714 / ...

 $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); 
+3
source

Source: https://habr.com/ru/post/986712/


All Articles