Created
July 26, 2019 14:04
-
-
Save SimonXIX/c03b438b15270a4bf3e874df320ae17c to your computer and use it in GitHub Desktop.
Testing the EPrints RESTful API for Users
This file contains hidden or 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 | |
# @name: eprints_rest.php | |
# @version: 0.1 | |
# @creation_date: 2019-07-22 | |
# @license: The MIT License <https://opensource.org/licenses/MIT> | |
# @author: Simon Bowie <[email protected]> | |
# @purpose: Testing the EPrints RESTful API | |
?> | |
<?php | |
$baseurl = 'xxxxxxxx'; | |
$service = 'user'; | |
$user_id = 'xxxxxxxx'; | |
$function = 'ref_category.xml'; | |
$username = 'xxxxxxxx'; | |
$password = 'xxxxxxxx'; | |
$fullurl = 'http://' . $baseurl . '/' . $service . '/' . $user_id . '.xml'; | |
#GET using cURL | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $fullurl); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_USERPWD, urlencode($username) . ':' . urlencode($password)); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | |
$response = curl_exec($ch); | |
if (!curl_exec($ch)) { | |
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); | |
} | |
curl_close($ch); | |
$result = new SimpleXMLElement($response); | |
print_r($response); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment