tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons Http Client > Construct URI2

Construct URI2 

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 construct URI from its parts.

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

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;

public class CreateURITest2 {

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

    List<NameValuePair> queryParams = new ArrayList<NameValuePair>();
    queryParams.add(new BasicNameValuePair("one""1111"));
    queryParams.add(new BasicNameValuePair("two""2222"));
    queryParams.add(new BasicNameValuePair("three""3333"));
    URI uri = URIUtils.createURI(
        URLEncodedUtils.format(queryParams, "UTF-8")"my_fragment");
    System.out.println("uri : " + uri);


It gives the following output,
uri :



Books Recommendation

bl  br