Get content encoding for a URL connection in Java

Description

The following code shows how to get content encoding for a URL connection.

Example


import java.net.URL;
import java.net.URLConnection;
/*from   w ww.  jav  a  2s . c om*/
public class Main {

  public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.google.com");
    URLConnection uc = u.openConnection();
    System.out.println("Content-encoding: " + uc.getContentEncoding());
  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode