user4189631
user4189631

Reputation: 21

How to make hash content before query parameters by uribuilder when creating url

I use uribuilder object from apache.http.client to create url

example:www.xxx.com/#/path/?query=123

my code as follow

URIBuilder uriBuilder = new URIBuilder();
uriBuilder.setScheme("http");
uriBuilder.setHost(host);
uriBuilder.setFragment(path);
uriBuilder.addParameter(query,123);

but the result is www.xxx.com/?query=123#path, how can I get correct url as I expected by uribuilder or other java tool library.

Upvotes: 2

Views: 2149

Answers (1)

nille85
nille85

Reputation: 311

A valid URI needs to comply with the following structure:

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]

The URI you are trying to create looks like a URI used in a single page application. In that case, the query part is a part of the fragment.

You can create it like this:

URIBuilder uriBuilder = new URIBuilder();
uriBuilder.setScheme("http");
uriBuilder.setHost("www.xxx.com");
uriBuilder.setPath("/");
uriBuilder.setFragment("/path/?query=123");
URI uri = uriBuilder.build();

Upvotes: 3

Related Questions