Gaurav Sood
Gaurav Sood

Reputation: 690

programmatically add parameters to URL java

i have a java application in which i want to programmatically add URL parameters to a given base url, instead of string manipulation to form a url. i have heard that URIBuilder is the way to go, though I have not been able to get that class or the maven repository to that class anywhere? is that the way to go or is there any other method to get that done?

EDIT: i have heard of using apache http client utils URIBuilder and not the javax.ws URIBuilder class

Upvotes: 1

Views: 8167

Answers (2)

Stephan
Stephan

Reputation: 43033

Drop this dependency in your pom to get UriBuilder:

 <dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>jsr311-api</artifactId>
    <version>1.1.1</version><!-- Select the version you want here -->
 </dependency>

More info: http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api

The Apache version is part of the httpcomponents:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.3.1</version>
</dependency>

More info: http://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/

Upvotes: 1

user1596371
user1596371

Reputation:

You can use java.net.URL to create a URL. The set() method allows you to set query parameters.

Upvotes: 0

Related Questions