Created
December 3, 2015 07:40
-
-
Save wpride/fd3d3fb0275b7e7872f8 to your computer and use it in GitHub Desktop.
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
public static String getCases(){ | |
try{ | |
String responseAccumulator = ""; | |
String baseURL = "https://www.commcarehq.org/a/%s/api/v0.5/case/?format=xml&limit=100"; | |
String queryURL = String.format(baseURL, domain); | |
String authString = username + ":" + password; | |
System.out.println("auth string: " + authString); | |
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); | |
String authStringEnc = new String(authEncBytes); | |
System.out.println("Base64 encoded auth string: " + authStringEnc); | |
URL url = new URL(queryURL); | |
URLConnection urlConnection = url.openConnection(); | |
urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc); | |
InputStream is = urlConnection.getInputStream(); | |
InputStreamReader isr = new InputStreamReader(is); | |
int numCharsRead; | |
char[] charArray = new char[1024]; | |
StringBuffer sb = new StringBuffer(); | |
while ((numCharsRead = isr.read(charArray)) > 0) { | |
sb.append(charArray, 0, numCharsRead); | |
} | |
String result = sb.toString(); | |
System.out.println("*** BEGIN ***"); | |
System.out.println(result); | |
System.out.println("*** END ***"); | |
return result; | |
} | |
catch(Exception e){ | |
return "Exception: " + e; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment