Last active
November 16, 2016 15:58
-
-
Save calimaborges/b07b26bc3efa9e28e7a77bbfd410bbcd to your computer and use it in GitHub Desktop.
Simple 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 carlosborges.httpclient; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.PrintWriter; | |
import java.net.Socket; | |
public class App { | |
public static void main( String[] args ) throws IOException { | |
Socket echoSocket = new Socket("localhost", 4567); | |
PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true); | |
BufferedReader in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); | |
out.print("GET / HTTP/1.1\r\n"); | |
out.print("Host: localhost\r\n"); | |
out.print("Accept: text/plain\r\n"); | |
out.print("\r\n\r\n"); | |
out.flush(); | |
String linha; | |
while ((linha = in.readLine()) != null) { | |
System.out.println(linha); | |
} | |
out.close(); | |
in.close(); | |
echoSocket.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment