What are some common mistakes to avoid when constructing and sending data via CURL in PHP?

One common mistake when constructing and sending data via CURL in PHP is not properly encoding the data before sending it. This can lead to errors or unexpected behavior when the data is received by the server. To avoid this, make sure to use functions like `http_build_query` or `json_encode` to properly encode the data before sending it.

// Constructing and sending data via CURL with proper encoding
$data = array(
    'key1' => 'value1',
    'key2' => 'value2'
);

$encoded_data = http_build_query($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/api');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data);

$result = curl_exec($ch);

curl_close($ch);