php – Google测量协议返回GIF89a ,D;
作者:互联网
我正在使用Google Measurement协议API保存展示次数.它工作正常,但虽然我没有回应任何东西它返回GIF89a ,D;这在页面上可见.知道如何隐藏这个吗?
我正在使用HTTP post请求发送数据.
$url = 'http://www.google-analytics.com/collect';
$fields_string = '';
$fields = array(
'v' => 1,
'tid' => 'UA-xxxxxxx-xx',
'cid' => xxx,
't' => 'event',
'ec' => 'category',
'ea' => 'impression',
'el' => 'label'
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
解决方法:
就目前而言,在进行cURL调用时,返回的信息将显示在屏幕上.如果你想避免使用CURLOPT_RETURNTRANSFER,那么你可以将返回的信息存储到变量中.
$result = curl_exec($ch);
因为你没有“告诉”卷曲,否则它只会将返回溢出到浏览器.
所以最后,你卷曲部分应该像这样:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url); //curl the url
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE); //return the transfer to be later saved to a variable
$result = curl_exec($ch);
标签:php,api,protocols,measurement 来源: https://codeday.me/bug/20190728/1559134.html