Http-Server如何创建请求头和响应头

|| SOS SOS SOS请! 我在Java中创建了一个原始的HttpServer,它侦听端口80并使用Get方法打开文件等(127.0.0.1/index.html)。现在我想从HTTP / 1.1(RFC 2616)协议创建请求标头(Accept,Accept Language,User-Agent)和响应标头(Content-Length和Cache-Control)。 你能帮我怎么做...你会救我的命!!!!!!!! 谢谢!     
已邀请:
标头只是初始GET / POST / *操作之后的行。最后一个标头与内容之间用空行分隔。因此,您需要做的(在客户端和服务器端)都是在内容之前在请求/响应中写几行。
HTTP/1.0 200 OK
Date: Fri, 31 Dec 1999 23:59:59 GMT
Content-Type: text/html
Content-Length: 1354

<html>
<body>
...
(more file contents)
附言Java具有内置的HTTP服务器,您知道吗? com.sun.net.HttpServer:
HttpServer httpServer = HttpServer.create(new InetSocketAddress(port), 5);
httpServer.createContext(\"/\", new MyRequestHandler());
httpServer.setExecutor(Executors.newCachedThreadPool());
httpServer.start();
    

要回复问题请先登录注册