java套接字输出中的奇怪数字

时间:2010-03-13 22:14:48

标签: java sockets

我有一个小测试应用程序:

Socket socket = new Socket("jeck.ru", 80);

PrintWriter pw = new PrintWriter(socket.getOutputStream(), false);
pw.println("GET /ip/ HTTP/1.1");
pw.println("Host: jeck.ru");
pw.println();
pw.flush();

BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));

String str;
while ((str = rd.readLine()) != null) {
    System.out.println(str);
}

它的输出:

HTTP/1.1 200 OK
Date: Sat, 13 Mar 2010 22:06:51 GMT
Content-Type: text/html;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=5
Server  HTTP/1.1 200 OK
Date: Sat, 13 Mar 2010 22:06:51 GMT
Content-Type: text/html;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=5
Server: Apache
Cache-Control: max-age=0
Expires: Sat, 13 Mar 2010 22:06:51 GMT

123
<!DOCTYPE html>
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Ваш IP</title>
</head>

<body>
        <div style='text-align: center; font: 32pt Verdana;margin-top: 300px'>
        Ваш IP &#151; 94.103.87.153     </div>
</body>
</html>

0

这些数字(123和0)是什么?

1 个答案:

答案 0 :(得分:3)

这些数字是以下结果:

Transfer-Encoding: chunked

有关详细信息和规范链接,请参阅Chunked transfer encoding