【问题标题】:Cannot post data correctly to Chargify via PHP cURL无法通过 PHP cURL 将数据正确发布到 Chargify
【发布时间】:2012-05-22 13:38:39
【问题描述】:

我想我没有正确发送 API 所需的数据。任何想法我做错了什么?

$ch = curl_init("https://test.chargify.com/customers.json");

$data = array(
  'first_name' => 'Test',
  'last_name' => 'User',
  'email' => 'user@test.com'
);

$data = json_encode($data);

curl_setopt_array($ch, array(
  CURLOPT_USERPWD => "yyyyyyyyyyyyyyy:x", // assume this is correct
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => $data,
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data)
  )
));

$output = curl_exec($ch);
curl_close($ch);

返回

{
errors: [
        "First name: cannot be blank.",
        "Last name: cannot be blank.",
        "Email address: cannot be blank."
    ]
}

以下是 API 的文档: http://docs.chargify.com/api-customers

【问题讨论】:

    标签: php api curl chargify


    【解决方案1】:

    试试这个:

    $data = array( 'customer' => array(
      'first_name' => 'Test',
      'last_name' => 'User',
      'email' => 'user@test.com'
    ));
    

    【讨论】:

    • 新鲜眼睛的力量!谢谢老兄。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    相关资源
    最近更新 更多