HttpUrlConnect gets response headers

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( "\nUse key to get response Header information\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 ();
        }
        

    }

}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326078269&siteId=291194637