1:写的程序读取不到文件,web服务器用的是tomcat,已经打开了,用浏览器也能正常访问到
Socket s=new Socket("127.0.0.1",8080);
PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
pw.println("GET /myweb/1.html HTTP/1.1");
pw.print("Accept: */*");
pw.println("Host: 127.0.0.1:8080");
pw.println("Connection: close");
pw.println();
InputStream ins=s.getInputStream();
byte[] buf=new byte[1024];
int len=ins.read(buf);
String str=new String(buf,0,len);
System.out.println(str);
s.close();
运行结果:
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
Date: Wed, 10 Apr 2019 14:11:40 GMT
Connection: close
0