Created
January 6, 2013 21:12
-
-
Save NetworksAreMadeOfString/4470277 to your computer and use it in GitHub Desktop.
A quick example of calling the proxy
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 void switchSomething(final int ID, final boolean toggle) | |
{ | |
((Thread) new Thread() | |
{ | |
public void run() | |
{ | |
try | |
{ | |
DefaultHttpClient client = new DefaultHttpClient(); | |
HttpParams params = new BasicHttpParams(); | |
SchemeRegistry registry = new SchemeRegistry(); | |
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); | |
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(params, registry); | |
DefaultHttpClient httpclient = new DefaultHttpClient(mgr, client.getParams()); | |
HttpGet request = null; | |
if(toggle) | |
{ | |
Log.i("switchSomething","On"); | |
request = new HttpGet("http://fictional.tld/telldus/on.php?deviceid=" + Integer.toString(ID)); | |
} | |
else | |
{ | |
Log.i("switchSomething","Off"); | |
request = new HttpGet("http://fictional.tld/off.php?deviceid=" + Integer.toString(ID)); | |
} | |
HttpResponse response = httpclient.execute(request); | |
String rawJSON = EntityUtils.toString(response.getEntity()); | |
response.getEntity().consumeContent(); | |
JSONObject TagObject = new JSONObject(rawJSON); | |
Log.i("JSON",TagObject.toString(3)); | |
} | |
catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
}).start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment