使用GuzzleHttp向Clevertap发出POST请求

时间:2016-02-18 09:58:22

标签: php laravel-5.1 guzzle clevertap

我正在使用Laravel 5.1和Guzzlehttp 6.1向clevertap发帖请求。

$client = new \GuzzleHttp\Client(['headers' => ['X-CleverTap-Account-Id' => '**********','X-CleverTap-Passcode'=>'*************8']]);



$result = $client->request('POST','https://api.clevertap.com/1/upload',["d"=>[
    "identity"=>"1189549",
      "ts"=>1419421212,
      "type"=>"profile",
      "profileData"=>[
        "Name"=>"Jack Montana",
        "Email"=>"jack@gmail.com",
        "Phone"=>"+14155551234",
        "Gender"=>"M",
        "Employed"=>"Y",
        "Education"=>"Graduate",
        "Married"=>"Y",
        "Age"=>28,
        "Customer Type"=>"Platinum",
      ]]]);

我得到以下错误。

  

客户端错误:POST https://api.clevertap.com/1/upload导致了错误   400 Bad Request回复:{"状态" :"失败" ,"错误" :"有效负载   是必须的"}

1 个答案:

答案 0 :(得分:1)

就像你在标题中发送ID / Token一样,必须在HTTP请求的主体内发送有效负载。

这样的事情:

$r = $client->request('POST', 'http://httpbin.org/post', [ 'body' =>'raw data' ]);

这应该返回200 OK并进行必要的更新。