1,浏览器的底层是:客户端;
2,服务器的底层就是:服务端;
3,HTTP协议在返回数据时的固定格式:
OutputStream outputStream = socket.getOutputStream();
OutputStream out = socket.getOutputStream();
out.write("HTTP/1.1 200 OK\r\n".getBytes());
//告诉浏览器这是一个网页,编码为utf-8
out.write("Content-Type:text/html;charset=utf-8\r\n".getBytes());
out.write("\r\n".getBytes());
4,代码示例:
public class Text01 {
public static void main(String[] args) throws IOException {
System.out.println("start");
ServerSocket serverSocket = new ServerSocket(9527);
while (true) {
Socket socket = serverSocket.accept();
//
OutputStream outputStream = socket.getOutputStream();
OutputStream out = socket.getOutputStream();
out.write("HTTP/1.1 200 OK\r\n".getBytes());
out.write("Content-Type:text/html;charset=utf-8\r\n".getBytes());
out.write("\r\n".getBytes());
out.write("<h1>ffffffffffffffffff<h1>".getBytes());
}
}
}