在curlopt_url中传递变量

时间:2016-09-20 12:03:13

标签: php json api php-curl postmates

我想在CURLOPT_URL中传递一个变量,这是我的代码

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.postmates.com/v1/customers/cus_KtQih0aARUZXdk/deliveries/$delivery_id/cancel",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => array(
    'pickup_address' => $_POST["pickup_address"],
    'pickup_phone_number' => $_POST["pickup_phone_number"],
    'pickup_name' => $_POST["pickup_name"],
    'dropoff_address' => $_POST["dropoff_address"],
    'dropoff_phone_number' => $_POST["dropoff_phone_number"],
    'dropoff_name' => $_POST["dropoff_name"],
    'manifest' => $_POST["manifest"]        
  ),
  CURLOPT_HTTPHEADER => array(
    "authorization: Basic MjhiMDU0ODktNjdkYS00M2VhLTg0NmMtYWQ1MWQ2MGNmMDA1Og==",
    "cache-control: no-cache",
    "content-type: multipart/form-data; boundary=---011000010111000001101001",
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);
$delivery_id = trim($_POST['show_name']);

curl_close($curl);
$response = json_decode($response);
$timestamp = json_decode($dateJSON, true);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response->fee;
}

我想在url中添加变量$delivery_id,但我对cURL不太熟悉,上面编写的代码无效。请告诉我在我的网址中包含此变量的方法。

0 个答案:

没有答案