Avatar ·

How to set custom headers in PHP cURL?

Hello everyone! I'm a beginner in PHP and trying to send a POST request to an external API via cURL. The API documentation says I need to pass several custom headers: `X-API-Key: mysecretkey`, `Content-Type: application/json`, and `Authorization: Bearer token123`. I tried passing them as a string in `curl_setopt($ch, CURLOPT_HTTPHEADER, ...)`, but it doesn't work — the server responds with a 400 Bad Request error or ignores my headers. Here's my current code: ```php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.example.com/data"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(["name" => "John"])); curl_setopt($ch, CURLOPT_HTTPHEADER, "X-API-Key: mysecretkey; Content-Type: application/json; Authorization: Bearer token123"); ```