不推荐使用 HttpMethod getResponseBodyAsString 但为什么
HttpMethod getResponseBodyAsString is not recommended but why
正在阅读 Apache 对 HttpClient 的建议 (http://hc.apache.org/httpclient-3.x/performance.html)
其中提到
Response streaming: It is recommended to consume the HTTP response body as a stream of bytes/characters using
HttpMethod#getResponseBodyAsStream method. The use of
HttpMethod#getResponseBody and HttpMethod#getResponseBodyAsString are
strongly discouraged.
但找不到相同的原因。我目前正在将 getResponseBodyAsString 与 GetMethod 一起使用,想知道我做错了吗?
来自文档:"HttpClient is capable of efficient request/response body streaming. Large entities may be submitted or received without being buffered in memory."
getResponseBodyAsString
方法要求 HttpClient 在内存中缓冲整个响应。基本上,您通过发送巨大的响应让 HTTP 服务器有机会使您的进程崩溃。
但是你必须做你必须做的。如果您的应用程序要求您将响应作为内存中的 String
处理,并且您确定响应不会太大(或者您愿意添加大小检查),那么就去做吧.
正在阅读 Apache 对 HttpClient 的建议 (http://hc.apache.org/httpclient-3.x/performance.html) 其中提到
Response streaming: It is recommended to consume the HTTP response body as a stream of bytes/characters using HttpMethod#getResponseBodyAsStream method. The use of HttpMethod#getResponseBody and HttpMethod#getResponseBodyAsString are strongly discouraged.
但找不到相同的原因。我目前正在将 getResponseBodyAsString 与 GetMethod 一起使用,想知道我做错了吗?
来自文档:"HttpClient is capable of efficient request/response body streaming. Large entities may be submitted or received without being buffered in memory."
getResponseBodyAsString
方法要求 HttpClient 在内存中缓冲整个响应。基本上,您通过发送巨大的响应让 HTTP 服务器有机会使您的进程崩溃。
但是你必须做你必须做的。如果您的应用程序要求您将响应作为内存中的 String
处理,并且您确定响应不会太大(或者您愿意添加大小检查),那么就去做吧.