When I send a normal HTTP request via a socket, the server does not respond with an OK response. I copied the HTTP header from Firefox. Here is the code:
Soc
The following fix, as mentioned by the previous answers, solves the problem;
pw.print("GET / HTTP/1.1\n\r\n"); pw.print("Host: stackoverflow.com\n\r\n");