-2

I have a webservice URL in which I have to pass a value having spaces

but webservice is terming it as illegal

 String path = java.net.URLDecoder.decode((CommonConstants.END_POINT_URL.concat(CommonConstants.DELETE_APPOINTMENT_REASON).replace("{id}", appointmentID).replace("{reason}", reason)),"UTF-8");
            WebTarget target = client.target(path);
            System.out.println(target);

targets gets printed as :

JerseyWebTarget { http://abc-def/SchServices/api/appointment/51574e11-b794-e411-824b-1cc1de6ebf5a?reason=Test Appointment Reason }

Spaces between test and appointment is not permitting it to hit webservice. URL encode is also not working....because it encodes complete thing...Please suggest

Crawling
  • 87
  • 11
  • possible duplicate of [Encoding URL query parameters in Java](http://stackoverflow.com/questions/5330104/encoding-url-query-parameters-in-java) – Joe Jan 05 '15 at 09:04

1 Answers1

0

Change

.replace("{reason}", reason))

to something like

.replace("{reason}", URLEncoder.encode(reason, "UTF-8")))

which will encode the spaces for the url. Spaces are illegal in a well-formed URL, and there are two possible encodings %20 or +.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249