我创建了一个http服务器,开启服务器,输入网页后,控制台打印出的信息如下,里面有好几个信息老有重复的,求解

昨夜的雨 2017-11-24 03:45:13
控制台信息:
POST /index.html HTTP/1.1
POST /index.html HTTP/1.1
Host: localhost:8081
POST /index.html HTTP/1.1
Host: localhost:8081
Connection: keep-alive
POST /index.html HTTP/1.1
Host: localhost:8081
Connection: keep-alive
Content-Length: 14
POST /index.html HTTP/1.1
Host: localhost:8081
Connection: keep-alive
Content-Length: 14
Cache-Control: max-age=0
POST /index.html HTTP/1.1
Host: localhost:8081
Connection: keep-alive
Content-Length: 14
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
POST /index.html HTTP/1.1
Host: localhost:8081
Connection: keep-alive
Content-Length: 14
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: null
POST /index.html HTTP/1.1
Host: localhost:8081
Connection: keep-alive
Content-Length: 14
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: null
Content-Type: application/x-www-form-urlencoded
POST /index.html HTTP/1.1
Host: localhost:8081
Connection: keep-alive
Content-Length: 14
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: null
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36
POST /index.html HTTP/1.1
Host: localhost:8081
Connection: keep-alive
Content-Length: 14
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: null
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
POST /index.html HTTP/1.1
Host: localhost:8081
Connection: keep-alive
Content-Length: 14
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: null
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
POST /index.html HTTP/1.1
Host: localhost:8081
Connection: keep-alive
Content-Length: 14
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: null
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.8

http服务器代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/*
* 创建服务器,并启动
*/
public class Server {
//声明服务器
private ServerSocket server;
private Socket client;
public static void main(String[] args) {

Server server = new Server();
server.start();



}
/*
* 启动方法
*/

public void start() {
try {
server = new ServerSocket(8081);
this.receive();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

/*
* 接受客户端
*/
private void receive() {

try {
client = server.accept();
StringBuilder sb = new StringBuilder();
String msg = null;//声明一个变量,用来表示接收客户端的请求信息
BufferedReader br = new BufferedReader(
new InputStreamReader(client.getInputStream()));
while((msg = br.readLine()).length() > 0) {
sb.append(msg);
sb.append("\r\n");

if(msg == null) {
break;
}
String requestInfo = sb.toString().trim();
System.out.println(requestInfo);

}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

/*
* 停止服务器
*/

public void stop() {

}



}

...全文
229 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

7,765

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧