Java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* Sample HTTPClient for OnDemand REST testing.
*
* (c) 2015 LoyaltyMatch, Inc
*
*
*/
public class HttpTestGet {
public static void main(String[] args) {
// key to api
String odpass="YOUR ODPASS";
String url = "YOUR URL/api/loyaltyprograms?format=json&odpass="+odpass;
// Create an instance of HttpClient.
DefaultHttpClient client = new DefaultHttpClient();
// Create a method instance.
HttpGet request = new HttpGet(url);
try{
// Execute the method.
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
// gets result of request
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println("The result is " + result.toString());
}catch (Exception e) {
System.out.println("An error has occurred: " + e.getMessage());
}
}
}
PHP
<?php
$odPass = "YOUR ODPASS";
$restUrl = "YOUR URL/api/loyaltyprograms?";
$url = $restUrl . "format=json&odpass=" . $odPass;
$ch=curl_init($url);
// enables certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
// checks the common name exists and matches the hostname for the server when verifying certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// The location of the root CA certificate for your site.
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "\SITE CERTIFICATE.cer");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$results=curl_exec($ch);
// Check if any error occured
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}else{
echo "The results are " . $results;
}
curl_close($ch);
?>