其他分享
首页 > 其他分享> > 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();
        }
    }

执行结果:

标签:状态,Http,String,URL,url,connection,str,responseCode,http
来源: https://blog.csdn.net/zhangjin1120/article/details/121581491