How can I display all the HTTP Headers when using the DefaultHTTPClient?

后端 未结 5 972
太阳男子
太阳男子 2020-12-30 12:21

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?

5条回答
  •  离开以前
    2020-12-30 13:14

    You can get all headers like this:

    Enumeration headerNames = request.getHeaderNames();
    while(headerNames.hasMoreElements()) {
      String headerName = (String)headerNames.nextElement();
      out.println("" + headerName);
      out.println("" + request.getHeader(headerName));
    }
    

    See this tutorial for more info.

提交回复
热议问题