Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a controller that takes 2 parameters -

@PostMapping(value = "/myEndPoint")
public ResponseEntity<StreamingResponseBody> process(final InputStream data,
                                                               @RequestParam final String param1,
                                                               @RequestParam final String base64Param)  {
    return ok().body(doSomething(base64Param.getBytes(), param1, data));
}

The base64Param String parameter will contain + characters, but of course the Spring controller replaces these with spaces.

Do you know how I can get around this and tell the controller to leave the + characters alone?

UPDATE - I tried

UriComponentsBuilder builder = fromUriString(format("http://localhost:%s/%s", serverPort, "/myEndPoint"))
            .queryParam("param1", param1)
            .queryParam("base64Param", Base64.getUrlEncoder().encodeToString(base64ParamValueWithPluses.getBytes()));

but I'm having to decode the base64Param parameter in my controller like this -

String decodedBaseParam64 = Base64.getUrlDecoder().decode(encodeBaseParam64);

Is there a way to encode this so Spring will decode it automatically with the + characters preserved?

question from:https://stackoverflow.com/questions/65831140/spring-controller-replacing-character-in-parameter-with-whitespace

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
148 views
Welcome To Ask or Share your Answers For Others

1 Answer

URI uri = fromUriString(format("http://localhost:%s/%s", serverPort, "/myEndPoint"))
            .queryParam("param1", param1)
            .queryParam("base64Param", "{base64Param}")
            .build(base64Param);

source - https://github.com/spring-projects/spring-framework/issues/21577


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...