title: Socket programming: 302 Found
body: <p>Im trying to connect to www.google.com using socket but the result is:</p>
  
  <p>HTTP/1.0 302 Found<br>
  Location: <a href="http://www.google.com.ph/" rel="nofollow">http://www.google.com.ph/</a><br>
  Cache-Control: private<br>
  Content-Type: text/html; charset=UTF-8</p>
  
  <p>Here's my Java test code:</p>
  
  <pre><code>    Socket sock = new Socket();  
      try {
          sock.connect(new InetSocketAddress("www.google.com", 80));
          InputStream in = sock.getInputStream();
          OutputStream out = sock.getOutputStream();
  
          out.write(new String("GET /\r\n").getBytes());
  
          byte[] readBuffer = new byte[4096];
          while(true) {
              int readSize = in.read(readBuffer);
              if(readSize &lt; 1) break;
              System.out.println(new String(readBuffer, 0, readSize));
          }
  
          sock.close();
      } catch(Exception e) {
  
      }
  </code></pre>
  
  <p>What's wrong with this? Btw, I need to achieve this using only sockets. tnx</p>