Skip to content

RESTClient - queryParams usage #33801

@vw98075

Description

@vw98075

We have the following code to retrieve data from a third party.

    // Full URL with symbol and query parameter structure
    String url = "https://query.theapp.theservice.com/v1/abc/foo/" + foo;

    // Prepare query parameters including the crumb and module type
    MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
    queryParams.add("boo", boo);

    // Execute the GET request using RestClient and pass full URL with query parameters
    ResponseEntity<String> response = restClient.get()
            .uri(uriBuilder -> uriBuilder
                    .replacePath(url)  // Use replacePath() with the full URL
                    .queryParams(queryParams)  // Add query parameters
                    .build())
            .header(HttpHeaders.USER_AGENT, "Mozilla/5.0")
            .retrieve()
            .toEntity(String.class);

With the above code, we get a runtime error:

I/O error on GET request for "https://query.theapp.theservice.com/v1/abc/foo/theFoo": Target host is not specified

We can't find queryParams, but @RequestParam in the document.

We don't know the correction of the following explanation of the error.

The error message "Target host is not specified" suggests that the URL is still not being constructed correctly. This often occurs when the URI handling within RestClient doesn't interpret the URL as fully qualified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.comstatus: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions