RestTemplate with encoded parameters
<p>I need to send an HTTP request to an authentication provider (Auth0). I want to get one specific user by its email address.</p>

<p>The request has to go to:</p>

<pre><code>curl -H "Authorization: Bearer ..." https://.../users?q=email%3A%22mymail%40abc.de%22&amp;search_engine=v2
</code></pre>

<p>I tried my luck with RestTemplate (Spring):</p>

<pre><code>public void doSomething() {
    ...

    Map&lt;String, String&gt; requestMap = new HashMap&lt;&gt;();
    requestMap.put("q", "email%3A%22mymail%40abc.de%22");
    requestMap.put("search_engine", "v2");

    RestTemplate restTemplate = getRestTemplateForRequestMap();

    HttpHeaders headers = getHeaders();
    HttpEntity&lt;Map&lt;String, String&gt;&gt; request = new HttpEntity&lt;&gt;(requestMap, headers);

    ResponseEntity&lt;UserInfo[]&gt; response = restTemplate.exchange(URI.create(baseApiUrl + "users"), HttpMethod.GET, request, UserInfo[].class);

    ...
}

private RestTemplate getRestTemplateForRequestMap() {
    RestTemplate restTemplate = new RestTemplate();
    List messageConverters = new ArrayList&lt;&gt;();
    messageConverters.add(new MappingJackson2HttpMessageConverter());
    restTemplate.setMessageConverters(messageConverters);

    return restTemplate;
}
</code></pre>

<p>Looks like the value of the <code>q</code> parameter needs to be encoded (they call it "Lucene query syntax"). I tried different variations. I even put them "hardcoded" encoded.</p>

<p>However it seems like the <code>q</code> parameter isn't working as the result includes not only the user with the specified email address but all users.
Headers are fine (otherwise I would get no user at all).</p>