Reading From and Writing To a URL

Reading From and Writing To a URL

A typical HTML page might contain text fields to send data to the server. The data is submitted by clicking the submit button on the Web page. The browser then writes the data to the URL over the network. The same thing came be done in a Java program using the URL class in package. To do this, you need an open connection to the URL. A connection can be opened by using the openConnection() method in the URL class. Using the following code, you can write information to a site directly without the help of the browser:

 import*;import*;public class Submit {    public static void main(String[] args) throws Exception	{           String data=URLEncoder.encode(args[0]);           URL url = new URL(


Share the Post: