Http状态码:简单获取http状态码

简单获取http状态码
Http状态码具体含义

    public static void main(String[] args) {
    
    
        try {
    
    
            String str = "https://www.baidu.com/";
            URL url = new URL(str);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            int responseCode = connection.getResponseCode();
            System.out.println(responseCode);
        } catch (Exception e) {
    
    
            e.printStackTrace();
        }
    }

执行结果:

Guess you like

Origin blog.csdn.net/zhangjin1120/article/details/121581491