使用DefaultHTTPClient时如何显示所有HTTP标头? [英] How can I display all the HTTP Headers when using the DefaultHTTPClient?

查看:120
本文介绍了使用DefaultHTTPClient时如何显示所有HTTP标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Apache Commons HTTP Client中的 DefaultHttpClient()时,是否可以在控制台输出中显示完整请求以进行调试?

When using the DefaultHttpClient() from the Apache Commons HTTP Client, is it possible to show the full request in the console output for debugging purposes?

我的应用程序出现问题,我觉得最简单的调试方法是检查 DefaultHTTPClient发送的所有数据

I'm having issues with my application and I feel that the easiest way to debug it it would be to inspect all data sent by the DefaultHTTPClient.

推荐答案

来自StackOverflow的另一个答案。这可以通过启用Apache HTTP Client的调试日志记录来轻松完成:

From another answer on StackOverflow. This can easily be done by enabling the debug logging for the Apache HTTP Client:

java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.FINEST);
java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.FINEST);

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug");

这篇关于使用DefaultHTTPClient时如何显示所有HTTP标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆