devxlogo

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 java.net 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 java.io.*;import java.net.*;public class Submit {    public static void main(String[] args) throws Exception	{           String data=URLEncoder.encode(args[0]);           URL url = new URL(

devx-admin

Share the Post: