zoukankan      html  css  js  c++  java
  • HttpUrlConnect获取响应头

    import java.io.IOException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.List;
    import java.util.Map;
    
    public class GetHeader {
    
        public static void main(String[] args) {
            
            URLConnection conn;
            try {
                URL obj = new URL("http://192.168.1.105:8010/eoffice10/server/public/api/");
                conn = obj.openConnection();
                Map<String, List<String>> map = conn.getHeaderFields();
    //            Map<String, List<String>> map2 = conn.getRequestProperties();
                
                System.out.println("显示响应Header信息...
    ");
                
                for (Map.Entry<String, List<String>> entry : map.entrySet()) {
                    System.out.println("Key : " + entry.getKey() + 
                            " ,Value : " + entry.getValue());
                }
                
                
                System.out.println("Authorization---->"+map.get("Authorization"));
                
                System.out.println("
    使用key获得响应Header信息 
    ");
                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 (IOException e) {
                e.printStackTrace();
            }
            
    
        }
    
    }
  • 相关阅读:
    Lua build and install
    tomcat 配置的另外一种方法
    debian vsftp
    git(1)
    jd-gui安装
    debian crash log查看
    ros学习笔记
    51nod 1138 连续整数的和(数学公式)
    51nod 1428 活动安排问题(优先队列)
    Codeforces Round #347 (Div. 2) (练习)
  • 原文地址:https://www.cnblogs.com/lxh520/p/8888916.html
Copyright © 2011-2022 走看看