0

我有一个关于获得整个响应大小的问题。

我试图使用 getHeader 函数来查找标头的 while 大小(字节),但是

我找不到标题的整个大小

http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html#getHeader%28java.lang.String

我正在使用 doPost 函数,它通过 request 和 response 。

我能够找到请求标头的内容但是,我不确定如何获取响应的内容(或大小)

有谁知道如何获取响应的字节大小或标头的内容?

谢谢

4

1 回答 1

0

You can wrap your servlet with a filter in two manners:

  • Convert the response object to org.apache.catalina.connector.Response, and call getBytesWritten(false). This is what the access log valve does (see implementation here). Notice this is the size of the response body only.
  • In the filter, Wrap the response with a caching response, that will cache the response body and headers. Then, after the request get the size. Again, this is the size of the response body only. You will have to construct the headers sizes yourself so expect some discrepancies.
于 2013-11-10T10:35:03.607 回答