Use Notifo’s API with Java
Posted in Development, Java, iPhone on January 8th, 2011 by admin – Be the first to commentThis is just a small hack to use Notifo’s API with Java:
URL url = new URL("https://api.notifo.com/v1/send_notification"); URLConnection connection = url.openConnection(); String authorizationString = "Basic " + new String(Base64.encodeBase64((username + ":" + apiSecret).getBytes())); connection.setRequestProperty("Authorization", authorizationString); connection.setDoOutput(true); OutputStreamWriter output = new OutputStreamWriter(connection.getOutputStream()); output.write("to=m"); output.write("&msg="+URLEncoder.encode(msg,"UTF8")); output.write("&uri="+URLEncoder.encode(uri,"UTF8")); output.write("&label="+URLEncoder.encode(label,"UTF8")); output.write("&title="+URLEncoder.encode(title,"UTF8")); output.flush(); output.close(); connection.getInputStream().close();
(Remember: This is just a quick’n'dirty solution. It just works for me and is not especially beautiful)
This code depends on Apache Commons for base64-encoding.
Feel free to drop me a line, if this was helpful. The code is released under WTFPL