Created
June 20, 2014 15:50
-
-
Save lnicola/90e1de002d6302b72f03 to your computer and use it in GitHub Desktop.
small Java HTTP client
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
| package httpclient; | |
| import java.io.InputStream; | |
| import java.net.URL; | |
| import java.net.URLConnection; | |
| public class HttpClient { | |
| public static void main(String[] args) { | |
| if (args.length != 1) { | |
| System.err.println("Usage: httpclient <url>"); | |
| return; | |
| } | |
| try { | |
| URL url = new URL(args[0]); | |
| URLConnection client = url.openConnection(); | |
| InputStream inputStream = client.getInputStream(); | |
| byte[] buf = new byte[1024]; | |
| for (int len; (len = inputStream.read(buf)) > 0;) { | |
| System.out.write(buf, 0, len); | |
| } | |
| } catch (Exception e) { | |
| e.printStackTrace(System.err); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment