Example usage for java.net URL openConnection

List of usage examples for java.net URL openConnection

Introduction

In this page you can find the example usage for java.net URL openConnection.

Prototype

public URLConnection openConnection() throws java.io.IOException 

Source Link

Document

Returns a java.net.URLConnection URLConnection instance that represents a connection to the remote object referred to by the URL .

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    URL u = new URL(args[0]);
    URLConnection uc = u.openConnection();
    BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
    String s = br.readLine();//from ww w . jav a2 s  .  c o  m
    while (s != null) {
        System.out.println(s);
        s = br.readLine();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String s;/*from  www.j ava 2s  .co  m*/
    s = "http://www.y.com/authTest";
    URL url = new URL(s);

    URLConnection urlc = url.openConnection();

    Map<String, List<String>> hf = urlc.getHeaderFields();
    for (String key : hf.keySet())
        System.out.println(key + ": " + urlc.getHeaderField(key));

    System.out.println(((HttpURLConnection) urlc).getResponseCode());
}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getRequestProperties());
}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getPermission());
}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getContentLengthLong());
}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getUseCaches());
}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getURL());
}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.toString());
}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getDate());
}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getReadTimeout());
}