PHP Using cURL in PHP POST Requests

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!


If you want to mimic HTML form POST action, you can use cURL.

// POST data in array
$post = [
    'a' => 'apple',
    'b' => 'banana'

// Create a new cURL resource with URL to POST
$ch = curl_init('');

// We set parameter CURLOPT_RETURNTRANSFER to read output
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Let's pass POST data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// We execute our request, and get output in a $response variable
$response = curl_exec($ch);

// Close the connection

Got any PHP Question?