Mega Code Archive

 
Categories / Java by API / Javax Net
 

Socket

/*  * Output:  *   *  HTTP/1.1 400 Bad Request Content-Type: text/html Date: Mon, 24 Apr 2006 23:11:15 GMT Connection: close Content-Length: 39 <h1>Bad Request (Invalid Hostname)</h1>  */ import java.io.InputStream; import java.io.OutputStream; import java.net.InetAddress; import java.net.Socket; public class MainClass {   public static void main(String args[]) throws Exception {     byte buff[] = new byte[1024];     InetAddress addr = InetAddress.getByName("www.rntsoft.com");     Socket s = new Socket(addr,80);     OutputStream output = s.getOutputStream();     InputStream input = s.getInputStream();     String GetCmd = "GET /index.html HTTP/1.0\r\n\r\n";     GetCmd.getBytes(0,GetCmd.length(),buff,0);     output.write(buff);     input.read(buff,0,buff.length);     System.out.println(new String(buff,0));   }      }