本帖最后由 月光海 于 2014-4-22 08:59 编辑
- import java.io.*;
- import java.net.*;
- class MyIE
- {
- public static void main(String[] args) throws Exception
- {
-
- Socket s=new Socket("192.168.1.101",8080);
- PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
- pw.println("GET /myweb/1.html HTTP/1.1");
- pw.println("Host: 192.168.1.101:8080");
- pw.println("Connection: closed");
- pw.println("Accept-Encoding: gzip,deflate,sdch");
- pw.println("Accept-Language: zh-CN,zh;q=0.8");
- pw.println("Accept: */*");
- pw.println();
- pw.println();
- BufferedReader brin=new BufferedReader(new InputStreamReader(s.getInputStream()));
- String line=null;
- while ((line=brin.readLine())!=null)
- {
- System.out.println(line);
- }
- s.close();
-
-
- }
- }
复制代码
我打开tomcat服务器,运行这个代码,显示的信息如下,数据已经获取到了,而且显示OK,那为什么会报了连接重置异常呢,我用毕老师的代码测试也是这样,这是什么情况呢,有没有人来指导下????
- C:\Users\Administrator\Desktop\bixiangdong>java MyIE
- HTTP/1.1 200 OK
- Server: Apache-Coyote/1.1
- Accept-Ranges: bytes
- ETag: W/"74-1398064623507"
- Last-Modified: Mon, 21 Apr 2014 07:17:03 GMT
- Content-Type: text/html
- Content-Length: 74
- Date: Mon, 21 Apr 2014 08:05:30 GMT
- Connection: close
- <html>
- <body>
- <title>
- </title><h1>这是我的主场</h1>
- </body>
- Exception in thread "main" java.net.SocketException: Connection reset
- at java.net.SocketInputStream.read(SocketInputStream.java:196)
- at java.net.SocketInputStream.read(SocketInputStream.java:122)
- at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
- at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
- at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
复制代码 |