Skip to content

Instantly share code, notes, and snippets.

@semperos
Created October 20, 2010 20:21
Show Gist options
  • Save semperos/637227 to your computer and use it in GitHub Desktop.
Save semperos/637227 to your computer and use it in GitHub Desktop.
Example using cURL library with PHP
<?php
$api_url = 'URL';
$token = 'TOKEN';
$curl_url = $api_url . '&token=' . $token;
// if you need to pull from a file, otherwise just generate the string
$content = file_get_contents('example.xml');
// cURL setup
$ch = curl_init($curl_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 108000);
// get response
$response_str = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
// print results
if($error == ''){
echo 'Success';
echo '<pre>' . $response_str . '</pre>';
}
else{
echo 'Error';
echo '<pre>' . $error . '</pre>';
echo '<pre>' . $response_str . '</pre>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment