http/1.0简单客户端

import java.net.*; import java.io.*; //import java.lang.*; public class Client { /** * @param args */ public static void main(String[] args){ // TODO Auto-generated method stub String s = null;   try { // String string =(new BufferedReader(new InputStreamReader(System.in))).readLine(); String string = "127.0.0.1"; Socket soc = new Socket(string, 8000); PrintWriter pw = new PrintWriter(new OutputStreamWriter(soc.getOutputStream())); BufferedReader br = new BufferedReader(new InputStreamReader(soc.getInputStream())); pw.print("GET /123.html HTTP/1.0 \r\n" + "Host:" + string + " \r\n\r\n"); pw.flush(); FileWriter fw =  new FileWriter("abc.txt"); while ((s = br.readLine()) != null) { if(s.equals("")){ break; } System.out.println(s); fw.write(s); fw.flush(); } /*while((s = br.readLine()) != null) { fw.write(s); fw.flush(); }*/ pw.close(); br.close(); soc.close(); } catch (Exception e) { e.printStackTrace(); } } }
相关文章
相关标签/搜索