1,浏览器的底层是:客户端;

2,服务器的底层就是:服务端;

3,HTTP协议在返回数据时的固定格式:

  1. OutputStream outputStream = socket.getOutputStream();
  2. OutputStream out = socket.getOutputStream();
  3. out.write("HTTP/1.1 200 OK\r\n".getBytes());
  4. //告诉浏览器这是一个网页,编码为utf-8
  5. out.write("Content-Type:text/html;charset=utf-8\r\n".getBytes());
  6. out.write("\r\n".getBytes());

4,代码示例:

  1. public class Text01 {
  2. public static void main(String[] args) throws IOException {
  3. System.out.println("start");
  4. ServerSocket serverSocket = new ServerSocket(9527);
  5. while (true) {
  6. Socket socket = serverSocket.accept();
  7. //
  8. OutputStream outputStream = socket.getOutputStream();
  9. OutputStream out = socket.getOutputStream();
  10. out.write("HTTP/1.1 200 OK\r\n".getBytes());
  11. out.write("Content-Type:text/html;charset=utf-8\r\n".getBytes());
  12. out.write("\r\n".getBytes());
  13. out.write("<h1>ffffffffffffffffff<h1>".getBytes());
  14. }
  15. }
  16. }