Quickest way to get content type

前端 未结 3 1136
感情败类
感情败类 2020-12-06 04:58

I need to chech for the content type (if it\'s image, audio or video) of an url which has been inserted by the user. I have a code like this:

URL url = new U         


        
3条回答
  •  时光说笑
    2020-12-06 05:50

    Thanks to DaveHowes answer and googling around about how to get HEAD I got it in this way:

    URL url = new URL(urlname);
    HttpURLConnection connection = (HttpURLConnection)  url.openConnection();
    connection.setRequestMethod("HEAD");
    connection.connect();
    String contentType = connection.getContentType();
    

提交回复
热议问题