Created
October 20, 2010 20:21
-
-
Save semperos/637227 to your computer and use it in GitHub Desktop.
Example using cURL library with PHP
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 | |
$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