Skip to content

Instantly share code, notes, and snippets.

@GiovanniK
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GiovanniK/788b1b20277337d54ac5 to your computer and use it in GitHub Desktop.
Save GiovanniK/788b1b20277337d54ac5 to your computer and use it in GitHub Desktop.
cURL post
<?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