Добавить параметр запроса в запрос WebClient - PullRequest
1 голос
/ 26 января 2020

Я использую Spring WebFlux, где я принимаю запрос, и использую тот же запрос для вызова другой службы. Но я не уверен, как добавить параметры запроса. Это мой код

@RequestMapping(value= ["/ptta-service/**"])
suspend fun executeService(request: ServerHttpRequest): ServerHttpResponse {

    val requestedPath = if (request.path.toString().length > 13) "" else request.path.toString().substring(13)

    return WebClient.create(this.dataServiceUrl)
                    .method(request.method ?: HttpMethod.GET)
                    .uri(requestedPath)
                    .header("Accept", "application/json, text/plain, */*")
                    .body(BodyInserters.fromValue(request.body))
                    .retrieve()
                    .awaitBody()
                    // But how about query parameters??? How to add those
}

Хотя код в Kotlin, Java также поможет.

1 Ответ

0 голосов
/ 26 января 2020

Вы можете добавить параметры запроса, используя лямбда-выражение в uri , для получения дополнительной информации см. WebClient.UriSpe c

 return WebClient.create(this.dataServiceUrl)
                .method(request.method ?: HttpMethod.GET)
                .uri(builder -> builder.path(requestedPath).queryParam("q", "12").build())
                .header("Accept", "application/json, text/plain, */*")
                .body(BodyInserters.fromValue(request.body))
                .retrieve()
                .awaitBody()
...