Skip to content

Instantly share code, notes, and snippets.

@peter279k
Last active December 21, 2015 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/a5248ee2471238fbd497 to your computer and use it in GitHub Desktop.
Save peter279k/a5248ee2471238fbd497 to your computer and use it in GitHub Desktop.
public void requestWeb() throws Exception {
url = "http://google.com";
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
Log.e("onFailure", "onFailure exception happened");
e.printStackTrace();
}
@Override
public void onResponse(final Response response) throws IOException {
if(response.isSuccessful() == false)
resultStr = "unexpected code: " + response;
else
resultStr = response.body().string();
runOnUiThread(new Runnable() {
@Override
public void run() {
responseTxt.setText(resultStr);
}
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment