POST 使用 GuzzleHttp 请求 Clevertap

POST request to Clevertap using GuzzleHttp

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

$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",
      ]]]);

我遇到以下错误。

Client error: POST https://api.clevertap.com/1/upload resulted in a 400 Bad Request response: { "status" : "fail" , "error" : "Payload is mandatory"}

就像您在 header 中发送 ID/Token 一样,必须在 HTTP 请求的 body 中发送负载。

像这样:

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

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