3

I am looking to build a URI of the type : https://example.com/index.html#db/report/csv?token=4cec23a8a07b63c1ed74&time=1473951700000&name=GA

but what I am trying is producing incorrect results :

UriBuilder.fromUri("https://example.com").path("index.html#db/report/csv").queryParam("token", "4cec23a8a07b63c1ed74").queryParam("time", "1473951700000").queryParam("name", "GA").build();

The above is encoding the # and resulting in

https://example.com/index.html%23db/report/csv?token=4cec23a8a07b63c1ed74&time=1473951700000&name=GA

How to not encode the # and still get the desired Url.

greperror
  • 5,156
  • 3
  • 20
  • 29
  • In your URL, the path is /index.html, and there is no query param. Only one long string masquerading a path followed by query params after the hash. What do you want this URI for? – JB Nizet Sep 17 '16 at 12:04
  • It points the user to a webpage, the pre-condition is I cannot change the link, it is a link to a third party web page, the requirement is to create the link dynamically by reading base(Uri and path/fragment) from config, and add query params dynamically. – greperror Sep 17 '16 at 12:13
  • Then do that with custom code, not with a URI builder. – JB Nizet Sep 17 '16 at 12:14
  • Ok, String Building seems to be the way go, thanks for the help, also I wanted to understand, is the required url malformed, as no library seems to be supporting to build it? – greperror Sep 17 '16 at 12:17
  • 1
    It's not malformed. But it's using a trick to simulate a path and query params in a single-page application (probably angular based) by putting them after the hash, which is normally used to refer to an anchor inside the page. – JB Nizet Sep 17 '16 at 12:24
  • How do you use the class UriBuilder? I am trying to build an URI myself and the IDE doesn't seem to recognize it but instead proposes me to change it to URLBuilder which I don't think is gonna work... @greperror – pensum Mar 10 '20 at 15:09

0 Answers0