/** [WebAccess.java] Copyright(c) 2000 WakuWaku. */ import java.net.*; import java.io.*; public class WebAccess { public static void main(String[] args) throws IOException{ String url,host,file; if(args.length>0) { url=args[0]; }else { System.out.println("引数を入れてください。"); return; } if(!url.startsWith("http://")) url="http://"+url; int j=url.indexOf("/",7); /* "http://"の次の/の場所を取得 */ host=url.substring(7,j); /* ホスト名を代入 */ file=url.substring(j); /* ファイル名を代入 */ Socket sock; try { sock=new Socket(host,80); }catch(UnknownHostException e) { System.out.println("サーバが見つかりません - "+host); return; } String dat; PrintWriter out=new PrintWriter(sock.getOutputStream()); out.println("GET "+file); /* この後に続けてHTTP/1.0と送るとそのHTMLの情報も送られてくる */ out.flush(); BufferedReader in=new BufferedReader( new InputStreamReader( sock.getInputStream())); while((dat=in.readLine())!=null) System.out.println(dat); out.close(); /* 必ずここでクローズする */ in.close(); sock.close(); } }