本文整理汇总了Java中org.apache.commons.httpclient.HttpMethod.getResponseHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.getResponseHeaders方法的具体用法?Java HttpMethod.getResponseHeaders怎么用?Java HttpMethod.getResponseHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.getResponseHeaders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doService
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private void doService(HttpMethod method, HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
outputRequestLog(req);
InputStream iStream = null;
ServletOutputStream oStream = null;
try {
long threadID = Thread.currentThread().getId();
log.debug("[" + threadID + "] forwarded to " + distributer.getRedirectUrl(req));
HttpClient client = new HttpClient();
log.debug("[" + threadID + "]send request.");
int resultCode = client.executeMethod(method);
log.debug("[" + threadID + "]got response: result code is " + resultCode);
res.setStatus(resultCode);
for (Header header : method.getResponseHeaders()) {
res.setHeader(header.getName(), header.getValue());
}
iStream = method.getResponseBodyAsStream();
oStream = res.getOutputStream();
writeOutputStream(iStream, oStream);
log.debug("[" + threadID + "] response sent to client.");
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new ServletException(e.getMessage(), e);
} finally {
if (iStream != null) {
iStream.close();
}
if (oStream != null) {
oStream.close();
}
}
}