Java HTTP Read getContentTypeFromUrl(String urlname)

Here you can find the source of getContentTypeFromUrl(String urlname)

Description

get Content Type From Url

License

Apache License

Declaration

public static String getContentTypeFromUrl(String urlname) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {

    public static String getContentTypeFromUrl(String urlname) throws IOException {
        URL url = new URL(urlname);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        try {/*from  w w w. j  ava 2  s .c o m*/
            connection.setRequestMethod("HEAD");
            connection.connect();
            return connection.getContentType();
        } finally {
            connection.disconnect();
        }
    }
}

Related

  1. getContentFromURL(String sURL)
  2. getContentFromURL(String url)
  3. getContentLength(URL url)
  4. getContentLength(URLConnection con)
  5. getContents(String urlStr)
  6. getContentTypeSpecified(URLConnection connection)
  7. getContentWithPost(String urls, Map pv)
  8. getData(String urlString)
  9. getHtmlByteArray(final String url)