Created
May 25, 2022 13:18
-
-
Save paulgrammer/ebd552062cd831754e426c9800b9748d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// API URL | |
$url = 'http://localhost/post-path'; | |
// Create a new cURL resource | |
$ch = curl_init($url); | |
// Setup request to send json via POST | |
$data = array( | |
'name' => 'test' | |
); | |
$payload = json_encode($data); | |
// Attach encoded JSON string to the POST fields | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); | |
// Set the content type to application/json | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); | |
// Return response instead of outputting | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
// Execute the POST request | |
$result = curl_exec($ch); | |
// log result | |
var_dump($result); | |
// Close cURL resource | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment