Skip to content

Instantly share code, notes, and snippets.

@rahuladams
Created April 29, 2020 10:08
Show Gist options
  • Save rahuladams/9f9c56a5779870fbba695438db3017b0 to your computer and use it in GitHub Desktop.
Save rahuladams/9f9c56a5779870fbba695438db3017b0 to your computer and use it in GitHub Desktop.
$params = array (
'parameter_one' => 'some_value',
'parameter_two' =>
array (
'parameter_array_option' => $some_variable,
)
);
//JSON encoded
$payload = json_encode($params);
$curl = curl_init();
$url = $data['url'];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://API_URL",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
//echo $response;
curl_close($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment