tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons Http Client > How to parse URI Query Parameters

How to parse URI Query Parameters 

Commons Http Client is a HTTP agent implementation in java supporting client-side authentication, HTTP state management and HTTP connection management. This requires the libraries httpclient-4.1.2.jar, httpcore-4.1.2.jar, httpmime-4.1.2.jar, httpclient-cache-4.1.2.jar, commons-codec.jar and commons-logging-1.1.1.jar to be in classpath. The following example shows how to parse URI Query parameters.

File Name  :  
com/bethecoder/tutorials/commons_httpclient/ParseURIQueryParametersTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.commons_httpclient;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;

public class ParseURIQueryParametersTest {

  /**
   @param args
   @throws URISyntaxException 
   */
  public static void main(String[] argsthrows URISyntaxException {

    String url = "http://www.example.com/something.html?one=11111&two=22222&three=33333";
    List<NameValuePair> params = URLEncodedUtils.parse(new URI(url)"UTF-8");
    
    for (NameValuePair param : params) {
      System.out.println(param.getName() " : " + param.getValue());
    }
  }

}
   

It gives the following output,
one : 11111
two : 22222
three : 33333



 
  


  
bl  br