Skip to content

Instantly share code, notes, and snippets.

@bsphere
Last active December 27, 2015 12:09
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 bsphere/7324002 to your computer and use it in GitHub Desktop.
Save bsphere/7324002 to your computer and use it in GitHub Desktop.
public class MyHTTPClient {
private URL mUrl;
public MyHTTPClient(URL url) {
mUrl = url;
}
public String getString() throws IOException {
HTTPUrlConnection urlConnection = null;
URL url = new URL(mUrl, "/string");
try {
urlConnection = (HTTPUrlConnection) url.openConnection();
InputStream in = urlConnection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder out = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
out.append(line);
}
return out.toString();
} finally {
if (urlConnection != null) urlConnection.disconnect();
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment