以下是我的示例 HTTP 服务器。我需要删除响应中生成的“内容长度:”标头。我尝试了很多方法,但都没有成功。有没有办法从服务器响应中删除内容长度?
public class SimpleHttpServer {
public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(9000), 0);
server.createContext("/test", new TestHandler());
server.setExecutor(null); // creates a default executor
server.start();
}
static class TestHandler implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
byte[] response = "Welcome to Test Server..!!\n".getBytes();
t.sendResponseHeaders(200, response.length);
OutputStream os = t.getResponseBody();
os.write(response);
os.close();
}
}
}