本帖最后由 张学林 于 2013-3-11 12:17 编辑
请人帮我看下为啥和老毕的代码一样,打印的结果却不一样呢?- public static void main(String[] args) throws Exception{
- // TODO Auto-generated method stub
- Socket s = new Socket("101.17.57.49",8080);
-
- PrintWriter out = new PrintWriter(s.getOutputStream(),true);
-
- out.println("GET /myweb/demo.html HTTP/1.1");
- out.println("Accept: */*");
- out.println("Accept-Language: zh-cn");
- out.println("Host: 101.17.57.49:11000");
- out.println("Connection: closed");
-
- out.println();
- out.println();
-
- BufferedReader bufr = new BufferedReader(new InputStreamReader(s.getInputStream()));
-
- String line = null;
-
- while((line=bufr.readLine())!=null){
- System.out.println(line);
- }
- s.close();
- }
复制代码 后面的是打印结果
D:\Java\day24>java MyIE
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Accept-Ranges: bytes
ETag: W/"262-1361953957612"
Last-Modified: Wed, 27 Feb 2013 08:32:37 GMT
Content-Type: text/html
Content-Length: 262
Date: Wed, 27 Feb 2013 08:43:58 GMT
Connection: close
<html>
<body>
<h1>这是我的主页</h1>
<font size=5 color=red>欢迎光临</font>
<div>
朝秦暮楚 工朝秦暮楚 震荡工 鞢载</br>
桌面上找到我的电脑,右击鼠标选择->属性,->高级->系统...</b
r>
重新装 jdk,安装完 jdk</br>
</div>
</body>
</html>
Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at MyIE.main(MyIE.java:30)
|
|