// 状态码,200代表请求成功
out.write("HTTP/1.1 200 OK\n".getBytes());
// 返回主题文件类型及字符编码
out.write("Content-Type: text/html;charset=UTF-8\n".getBytes());
byte[] body = "<h1>index page</h1><a href='http://jd.com'>JD</a>".getBytes();
// 返回的主题长度
out.write(("Content-Length: " + body.length + "\n" ).getBytes());
// 头和主体之间要有一个"回车 + 换行"
out.write("\r\n".getBytes());
// 主体
out.write(body);
客户端给浏览器返回页面请求
最新推荐文章于 2024-03-16 12:05:53 发布