A simple java snippet for posting commands to jubito server from an android application.
String jubito_Host = "http://192.168.1.98:8080/www/index.html";
String jubito_Username = "your_jubito_username";
String jubito_Password = "your_jubito_password";
String jubito_Command = "%checkin%"; // Your custom Instruction Set or a simple system function
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(jubito_Host + "?cmd=" + URLEncoder.encode(jubito_Command.toLowerCase(), "UTF-8"));
String credentials = jubito_Username + ":" + jubito_Password;
String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
httppost.addHeader("Authorization", "Basic " + base64EncodedCredentials);
HttpResponse httpresponse = httpclient.execute(httppost);
String result = EntityUtils.toString(httpresponse.getEntity());
return result;
} catch (UnsupportedEncodingException e) {
// suppress exception
} catch (Exception e) {
e.printStackTrace();
}
return null;
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.