本帖最后由 格子、 于 2014-6-12 19:34 编辑
今天学到网络编程的模拟IE访问Tomcat的阶段,我是win764的系统,安装好了Tomcat,也配置并启动好了,在webapps建立的文件夹中的html文件在浏览器也能正常访问,不知道为什么模拟IE访问的时候,之后返回的是打印的Socket信息,调试了半天也不知道是什么情况,大家有没有遇到这中情况?
代码如下;
- import java.io.*;
- import java.net.*;
- class MyIE
- {
- public static void main(String[] args) throws Exception
- {
- //创建客户端
- Socket s= new Socket(InetAddress.getByName("gezi-PC"),8080);
- //定义网络输出流
- PrintWriter out = new PrintWriter(s.getOutputStream(),true);
- //定义文件读取流
- BufferedReader read =
- new BufferedReader(new InputStreamReader(s.getInputStream()));
-
- //开始发送数据
- out.println("GET /myweb/index.html HTTP/1.1");
- out.println("Accept: */*");
- out.println("Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
- out.println("Host: localhost:8080");
- out.println("Connection: keep-alive");
- out.println();
- out.println();
- //读取文件
- String str = null;
- while((str = read.readLine())!=null)
- {
- System.out.println(s);
- }
-
- s.close();
- }
- }
复制代码
|