Last active
August 29, 2015 14:03
-
-
Save GiovanniK/788b1b20277337d54ac5 to your computer and use it in GitHub Desktop.
cURL post
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 | |
$data['var'] = urlencode($_POST['var']); | |
$ch = curl_init(); | |
$url = 'API_URL'; | |
//set the url, number of POST vars, POST data | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, count($data)); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, '', '&')); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
//execute post | |
$result = curl_exec($ch); | |
//close connection | |
curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment