简体   繁体   中英

Calling a GET Rest service using apiClient from my java application. If I have '&' as part of input param. Its taking it as separator

I am consuming a GET Rest API. I have imported the client api and using it to call the service. If I have & as part of input like "1 & 2" . Its not getting encoded and the source is receiving the param as just 1. When I use swagger ui to call the same method its working fine.

I am completely new to web-services. Please let me know If I missed some necessary details for everybody to understand my problem. We are using swagger code-gen to generate client api.

String code = "1 & 2";

String productId = productControllerApi.getAllProductIdUsingGET(null, null, null, code);

What should I do so that getAllProductIdUsingGET receives parameter as 1 & 2 ?

I tried

URLEncoder.encode(code, CharEncoding.UTF_8);

but now getAllProductIdUsingGET receives parameter as 1+%26+vikram and don't give me the necessary output.

Is there anything I can do at the consumer side or is it the source that has to handle?

You should send encoded String to Rest API, and then use:

String decoded = java.net.URLDecoder.decode(code , "UTF-8");
String productId = productControllerApi.getAllProductIdUsingGET(null, null, null, decoded);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM