在curlopt_url中传递变量



我想在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不太熟悉,上面写的代码不起作用。请告诉我如何在我的url中包含这个变量

有一次我也犯了同样的错误。使用的解决方案是: - 撇号 -dot-在变量前后。这样的:

/交付/"delivery_id美元。"

/取消

相关内容

  • 没有找到相关文章

最新更新