Last active
December 27, 2015 12:09
-
-
Save bsphere/7324002 to your computer and use it in GitHub Desktop.
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
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