URLConnection : URL : Network Protocol : Java examples (example source code) Organized by topic

Java
C++
Java Home »  Network Protocol   » [  URL  ]  Screenshots 
 



URLConnection

/* From http://java.sun.com/docs/books/tutorial/index.html */


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

public class Reverse {
  public static void main(String[] argsthrows Exception {

    if (args.length != 1) {
      System.err.println("Usage:  java Reverse " "string_to_reverse");
      System.exit(1);
    }

    String stringToReverse = URLEncoder.encode(args[0]);

    URL url = new URL("http://java.sun.com/cgi-bin/backwards");
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);

    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.println("string=" + stringToReverse);
    out.close();

    BufferedReader in = new BufferedReader(new InputStreamReader(connection
        .getInputStream()));
    String inputLine;

    while ((inputLine = in.readLine()) != null)
      System.out.println(inputLine);

    in.close();
  }
}
           
       
Related examples in the same category
1.  URL Constructor Test
2.  URL Encode Test
3.  Get URL Content
4.  Get URL Parts
5.  Read from a URL
6.  URL Equality
7.  URL Request
8.  URL Get
9.  URL Reader
10.  URL Connection Reader URL Connection Reader
11.  Parse URL Parse URL








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.