我想通过使用WWW-Authenticate: Basic
标头在 Web 浏览器中验证套接字连接,但没有出现输入用户名和密码的提示。怎么做?
public static void responseView(Socket socket) throws IOException {
responseHeaders(200);
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
for(String header : headers) {
outputStream.writeBytes(header + "\r\n");
}
outputStream.writeBytes("\r\n");
outputStream.writeBytes("<!DOCTYPE html><html><head><title>Java Web Server</title></head><body></body></html>");
outputStream.writeBytes("\r\n");
outputStream.flush();
}
public static void responseHeaders(int statusCode) {
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
headers.add("HTTP/1.0 " + Integer.toString(statusCode) + " " + Config.STATUS_CODES.get(statusCode));
headers.add("Content-Type: text/html");
headers.add("Date: " + formatter.format(new Date(System.currentTimeMillis())));
headers.add("Server: Simple Java Web Server");
headers.add("WWW-Authenticate: Basic");
}