· 6 years ago · Aug 28, 2019, 06:48 AM
1// Set output as text
2header("Content-Type: text/plain");
3
4// Roundsman ID and API key
5$roundsmanID = 129;
6$roundsmanApiKey = '7efkhMWM';
7
8// Prepare params - get roundsman details
9$url = 'https://parker.jojbre.com/api/roundsman/get-details';
10$params = array();
11$params['username'] = 'milkman';
12$params['password'] = '12345';
13$params['outputFormat'] = 'xml';
14$params['requestMethod'] = 'get';
15
16// Sort arrays by key
17ksort($params);
18
19// Get all values into string
20$values = implode('',$params);
21
22// Get cURL resource
23$curl = curl_init();
24
25// Full url with params
26$fullUrl = $url.'?'.http_build_query($params);
27
28// Set curl options
29curl_setopt_array($curl, array(
30 CURLOPT_RETURNTRANSFER => TRUE,
31 CURLOPT_URL => $fullUrl,
32 CURLOPT_SSL_VERIFYPEER => false, // remove in live version
33 CURLOPT_SSL_VERIFYHOST => false, // remove in live version
34));
35
36// Send the request & save response to $resp
37$resp = curl_exec($curl);
38
39// Check curl errors
40if(!curl_exec($curl)) {
41 die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
42}
43
44// Close request to clear up some resources
45curl_close($curl);
46
47// Convert XML to array
48$xml = simplexml_load_string($resp, 'SimpleXMLElement', LIBXML_NOCDATA);
49
50// Output API link
51echo 'HTTP GET request: '.PHP_EOL.$fullUrl.PHP_EOL.PHP_EOL;
52
53// Output reponse
54echo 'Response:';
55echo PHP_EOL;
56print_r($xml);