corda/sgx-jvm/avian/test/extra/Sockets.java
Andras Slemmer 9bb3d6b972 Add 'sgx-jvm/avian/' from commit '09e4fe60d01f4f4bfb6b2976973bb4913ef61edc'
git-subtree-dir: sgx-jvm/avian
git-subtree-mainline: f978eab8d1
git-subtree-split: 09e4fe60d0
2017-03-13 12:18:24 +00:00

41 lines
1.1 KiB
Java

package extra;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class Sockets {
/**
* @param args
* @throws IOException
* @throws UnknownHostException
*/
public static void main(String[] args) throws UnknownHostException,
IOException {
System.out.print("Requesting... " + args[0] + "\n");
Socket sock = new Socket(args[0], 80);
try {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
String request = "GET /?gws_rd=cr HTTP/1.1\r\n"
+ "Host: " + args[0] + "\r\n" + "Accept: */*\r\n"
+ "User-Agent: Java\r\n" + "Connection: close\r\n" + "\r\n";
bw.write(request);
bw.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String read = null;
while ((read = br.readLine()) != null) {
System.out.println(read);
}
bw.close();
} finally {
sock.close();
}
}
}