Created
April 24, 2013 16:41
-
-
Save emil10001/5453576 to your computer and use it in GitHub Desktop.
Playing around with Square's OkHttp library.
This file contains hidden or 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
| OkHttpClient client = new OkHttpClient(); | |
| // Ignore invalid SSL endpoints. | |
| client.setHostnameVerifier(new HostnameVerifier() { | |
| @Override | |
| public boolean verify(String s, SSLSession sslSession) { | |
| return true; | |
| } | |
| }); | |
| // Create request for remote resource. | |
| HttpURLConnection connection; | |
| connection = client.open(new URL(ENDPOINT)); | |
| InputStream is = connection.getInputStream(); | |
| InputStreamReader isr = new InputStreamReader(is); | |
| // from StackOverflow: http://stackoverflow.com/a/2549222 | |
| BufferedReader r = new BufferedReader(isr); | |
| StringBuilder total = new StringBuilder(); | |
| String line; | |
| while ((line = r.readLine()) != null) { | |
| total.append(line); | |
| } | |
| response = total.toString(); | |
| BusProvider.getInstance().post(result); |
This file contains hidden or 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
| @Subscribe | |
| public void dumpOutput(String output) { | |
| textView.setText(output); | |
| } |
This file contains hidden or 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
| BusProvider.getInstance().register(this); | |
| new BackgroundWebRunner().execute(null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment