获取HttpResponseHeader属性

/**
 *
 * @author Cache John
 * @email
[email protected]
 *
 */
public class GetHttpResponseHeader
{
   
    public static void main(String[] args)
    {
        try
        {
           
            URL obj = new URL("
http://www.huawei.com ");
            URLConnection conn = obj.openConnection();
           
            Map<String, List<String>> map = conn.getHeaderFields();
           
            System.out.println("显示响应Header信息\n");
           
            for (Map.Entry<String, List<String>> entry : map.entrySet())
            {
                System.out.println("Key : " + entry.getKey() + " ,Value : " + entry.getValue());
            }
           
            System.out.println("\n使用key获得响应Header信息 \n");
            List<String> server = map.get("Server");
           
            if (server == null)
            {
                System.out.println("Key 'Server' is not found!");
            }
            else
            {
                for (String values : server)
                {
                    System.out.println(values);
                }
            }
           
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
       
    }
   
}

你可能感兴趣的:(java,header,url,ResponseHeader)