当前位置:   article > 正文

HttpUrlConnect获取响应头

httpurlconnection 获取响应头
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信息...\n");
            
            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("\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 (IOException e) {
            e.printStackTrace();
        }
        

    }

}

 

转载于:https://www.cnblogs.com/lxh520/p/8888916.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/210805
推荐阅读
相关标签
  

闽ICP备14008679号