Curl返回成功,但API调用失败


Curl returns success, but API call fails

我正在使用Webex的URL API,由于某种原因,当编写一个简单的PHP cURL请求到URL时,API返回失败。但是,如果我将相同的post参数传递给表单,并且表单的action属性等于该API端点,则API返回success。

下面是form方法:
  <form action="xxxxxxx987" name="hidden_form" method="post">
      <input value="EN" name="AT" type="hidden" />
      <input value="xxxxxxx987" name="MK" type="hidden" />
      <input value="<?php echo $email; ?>" name="AE" type="hidden" />
      <input value="<?php echo $firstname; ?>" name="FN" type="hidden" />
      <input value="<?php echo $lastname; ?>" name="LN" type="hidden" />
      <input value="<?php echo $company; ?>" name="CO" type="hidden" />
      <input value="http://mysite.com/resources/thank_you" name="BU" type="hidden" />
  </form>

这是cURL方法:

$url = "https://mysite.com/m.php";
//Data Array
$postParams = array("AT"=>"EN",
                    "MK"=>"xxxxxxx987",
                    "AE"=>"my@email.com",
                    "FN"=>"fname",
                    "LN"=>"lname",
                    "CO"=>"my company",
                    "BU"=>"http://192.168.x.x/resources/thank_you");
//Encode Query Data
$data = http_build_query($postParams);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true); //True For Regular HTTP Post
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded", "Content-length: ".strlen($data)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
if($result) {
    echo '<h3>Status: Curl Succeeded</h3>';
    print 'Result: '.$result;
}

的问题:为什么API失败时,我卷曲它,为什么它成功时,使用它作为表单post动作?cURL方法有什么问题?

您不需要http_build_query,因为CURLOPT_POSTFIELDS接受数组