Skip to content

Instantly share code, notes, and snippets.

@emil10001
Created April 24, 2013 16:41
Show Gist options
  • Select an option

  • Save emil10001/5453576 to your computer and use it in GitHub Desktop.

Select an option

Save emil10001/5453576 to your computer and use it in GitHub Desktop.
Playing around with Square's OkHttp library.
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);
@Subscribe
public void dumpOutput(String output) {
textView.setText(output);
}
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