Created
July 3, 2018 00:37
-
-
Save Prid13/f5fa84a68b072abaac1414c11bbbc934 to your computer and use it in GitHub Desktop.
cURL POST Request
This file contains 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 | |
// eksempel kode på INSERT til Candidate (legge til ny candidate) | |
$url = "https://api.recman.no/v2/post/candidate"; | |
// lager en array med alle variablene vi sender med. Har kopiert fra eksempel til Insert på recman | |
$data = array( | |
{ | |
"key": "YOUR_KEY", | |
"scope": "candidate", | |
"operation": "insert", | |
"data": { | |
"firstName": "Chris", | |
"lastName": "Reyes", | |
"email": "yugiohmaster@naruto.no", | |
"gender": "male" | |
} | |
} | |
); | |
// lager ny cURL objekt | |
$ch = curl_init($url); | |
// setter option for at vi skal ha resultat, til true (altså at den skal returnere noe) | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
// her velger vi hva slags HTTP-metode vi vil ha -- bruker POST her. | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
// sender med variablene i requesten | |
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data)); | |
// kjører requesten til nettsiden, og lagrer responsen | |
$response = curl_exec($ch); | |
if (!$response){ | |
// noe galt skjedde med requesten | |
echo "Error: Det skjedde noe galt!"; | |
} else { | |
// printer ut responsen | |
print_r($response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment