URLConnection addRequestProperty Example

URLConnection class addRequestProperty example. This example shows you how to use addRequestProperty method.


URLConnection class addRequestProperty example. public void addRequestProperty(String key, String value) Adds a general request property specified by a key-value pair. This method will not overwrite existing values associated with the same key.

Here is the code
/*
 * @ # AddRequestProperty.java
 * A class repersenting use to AddRequestProperty 
 * method of URLConnection class in java.net package
 * version 23 June 2008
 * author Rose India 
 */

import java.net.*;
import java.util.*;

public class AddRequestProperty {

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

        URL url = new URL("http://localhost:8080/net/listnets.jsp");
        URLConnection connection = url.openConnection();

        connection.addRequestProperty("name""komal");
        connection.addRequestProperty("class""10th");
        connection.addRequestProperty("Address""Delhi 17");

        Map map = connection.getRequestProperties();
        Set set = map.entrySet();

        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}

Output
name=[komal]
Address=[Delhi 17]
class=[10th]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US