I am learning about Java socket. I am trying to send an HTTPS GET request to Facebook, like this:
String request = "GET / HTTP/1.0\r\n"
+ "Host: www.facebook.com\r\n"
+ "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0\r\n"
+ "Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7\r\n"
+ "Accept-Language: de,en;q=0.7,en-us;q=0.3\r\n"
+ "Accept-Encoding: gzip\r\n"
+ "Connection: close\r\n\r\n";
byte[] Outdata = request.getBytes();
Socket server = new Socket("www.facebook.com", 443);
DataOutputStream outputStream = new DataOutputStream(server.getOutputStream());
outputStream.write(Outdata);
outputStream.flush();
And then, I try to listen to incoming data from the server, like this:
DataInputStream inputStream =
new DataInputStream(server.getInputStream());
byte[] InData = new byte[1024];
while (true) {
inputStream.read(InData);
String data = new String(InData, StandardCharsets.UTF_8);
System.out.println(data);
}
But I don't get any return data from the server. Why?