gpt4 book ai didi

php - 使用 Zend_Http_Client 时出现内容类型错误

转载 作者:可可西里 更新时间:2023-11-01 13:26:08 27 4
gpt4 key购买 nike

我正在尝试使用 Zend_Http_Client 和 POST 将数据发送到 Google Analytic 的收集器。我有一个数组 $postParams,其中包括我的跟踪 ID、cid 和命中类型,我通过 setParameterPost() 将此数组的值添加到我的客户端。

这是我的操作的相关部分:

$client = new Zend_Http_Client('https://ssl.google-analytics.com/debug/collect');
foreach ($postParams as $postParam => $postValue) {
$client->setParameterPost($postParam, $postValue);
}
$response = $client->request();

调用此脚本时出现以下错误:

Cannot handle content type '' automatically. Please use Zend_Http_Client::setRawData to send this kind of content.

它是在 Zend_Http_Client 的 _prepareBody() 方法中抛出的。当我添加一个 echo($this->enctype); die(); 在那里,我收到 NULL

我将添加 $client->setEncType(); 到我的代码中,但数据很简单。
有谁知道我在这里缺少什么?我真的必须使用 setRawData 吗?

提前致谢!

更新:$client->setParameterPost('postParams', $postParams); 也不会起作用。它会引发相同的错误。

最佳答案

这个答案让我回到正轨: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);

关于php - 使用 Zend_Http_Client 时出现内容类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30095209/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com