验证图片地址是否有效

2020-04-07  本文已影响0人  超音速6
/**
     * 判断网络图片是否存在
     * posturl 图片地址链接
     */
    public static String isImagesTrue(String posturl) throws IOException {
        URL url = new URL(posturl);
        HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
        urlcon.setRequestMethod("POST");
        urlcon.setRequestProperty("Content-type",
                "application/x-www-form-urlencoded");
        if (urlcon.getResponseCode() == HttpURLConnection.HTTP_OK) {
            System.out.println(HttpURLConnection.HTTP_OK + posturl
                    + ":posted ok!");
            return "200";
        } else {
            System.out.println(urlcon.getResponseCode() + posturl
                    + ":Bad post...");
            return "404";
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读