//到apache上去下载一个commons-httpclient包
import java.io.IOException;import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;/**
 * 用于打印服务器端返回的详细信息
 * @author Winter Lau
 */
public class HttpClientDump { /**
 * @param args
 * @throws IOException 
 * @throws HttpException 
 */
public static void main(String[] args) throws HttpException, IOException {
HttpClient client = new HttpClient();
String url = "http://www.csdn.net/index.htm";
GetMethod method1 = new GetMethod(url);
client.executeMethod(method1);
Header[] hs = method1.getResponseHeaders();
System.out.printf("Charset is %s\n",method1.getResponseCharSet());
System.out.printf("\n================ HEADERS ==================\n");
for(int i=0;i<hs.length;i++)
System.out.printf("\n%s = %s",hs[i].getName(),hs[i].getValue()); System.out.printf("\n================ BODY ==================\n");
System.out.println(method1.getResponseBodyAsString()); System.out.printf("\n================ END ==================\n");
}}