Google Analytics请求会正确验证,但从CURL发送时会返回错误

时间:2016-02-05 09:28:06

标签: php curl google-analytics

我向Google Analytics发送以下请求:

  

http://www.google-analytics.com/collect?v=1&tid=UA-72579327-1&cid=61baecac-8f8c-4dce-bf07-a7efa24a4e47&t=transaction&ti=qcY6pvpWGmP9fHyi&tr=10.00&cd1=Acme Racing& cd2 = http://www.domain.co.uk/affiliate/idevaffiliate.php/id=314&tid1=12044762460674420322&url=http://www.nitrotek.co.uk&cd3=A1&cd4=Upgrades&cd5=Acme-Tech& cd6 = {device}& cd7 =& cd8 = 0& cd9 =& cd10 =& cd11 =& cd12 = Nitrotek DSA& amp; ; CD13 = G&安培; CD14 = 50&安培; CD15 = 1&安培; CD16 = 85安培; CD17 = 12044762460674420322&安培; CD18 =安培; CD19 = http://www.domain.co.uk&cd20=61baecac-8f8c-4dce-bf07-a7efa24a4e47&gclid=

当您转到Google's hit builder并验证请求时,它会生效。

然而,当我通过CURL POST发送相同的请求时,我只得到" 400。那是一个错误。您的客户发出了格式错误或非法的请求。这就是我们所知道的。"。

POST是此请求的正确方法(虽然我以前尝试过GET),Content-Length标头是发送数据的长度(字符串)。这是代码:

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $transaction_url,    //the same URL string given above
    CURLOPT_POST => 1,
    CURLOPT_USERAGENT => 'cURL Request'
));
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Length: '.strlen($transaction_url)    //length of URL string
));
$trans_resp = curl_exec($curl);
var_dump($trans_resp);
curl_close($curl);

0 个答案:

没有答案