title: How to perform method exchange for RestTemplate in order to not change the uri
body: <p>In order to get Json Content from a xwiki Rest API, I used RestTemplate's method RestTemplate.exchange(..) but I get a 404 not found error. The Uri contains %2520 instead of %20.</p>
  
  <p>Here My code :</p>
  
  <pre><code>public static void main(String[] args) throws IOException{   
      private static final String link = "http://swininducasa02.ptx.fr.sopra:8080/xwiki-enterprise-web-8.4.5/rest/wikis/xwiki/spaces/Main/spaces/PIC/spaces/Serveur%20de%20virtualisation/spaces/Serveur%20de%20Marcoussis/spaces/choix/spaces/SGBFV/pages/WebHome";
      String plainCreds = "user:passwd";
      byte[] plainCredsBytes = plainCreds.getBytes();
      byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
      String base64Creds = new String(base64CredsBytes);
      HttpHeaders headers = new HttpHeaders();
      headers.add("Authorization", "Basic " + base64Creds);
      headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
      headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
  
      RestTemplate restTemplate = new RestTemplate();
      System.out.println("Begin /GET request!");
      HttpEntity&lt;String&gt; request = new HttpEntity&lt;&gt;(headers);
      ResponseEntity&lt;String&gt; response = restTemplate.exchange(link+ "?media=json", HttpMethod.GET, request, String.class);
      Map&lt;String, String&gt; map = new ObjectMapper().readValue(response.getBody(), Map.class);
      System.out.println( map.get("content"));
  }
  </code></pre>
  
  <p>I searched &amp; I found that the problem refers to the Content-Type . I tried all of the following lines but it is still not working.</p>
  
  <p>headers.add("Content-type",MediaType.APPLICATION_JSON_UTF8_VALUE);</p>
  
  <pre><code>headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
  UriComponents uriComponents = UriComponentsBuilder.fromPath(link).build(true);
  URI uri= uriComponents.toUri();
  </code></pre>
  
  <p>Here is the link that i want to access:</p>
  
  <p><a href="http://swininducasa02.ptx.fr.sopra:8080/xwiki-enterprise-web-8.4.5/rest/wikis/xwiki/spaces/Main/spaces/PIC/spaces/Serveur%20de%20virtualisation/spaces/Serveur%20de%20Marcoussis/spaces/choix/spaces/SGBFV/pages/WebHome?media=json" rel="nofollow noreferrer">http://swininducasa02.ptx.fr.sopra:8080/xwiki-enterprise-web-8.4.5/rest/wikis/xwiki/spaces/Main/spaces/PIC/spaces/Serveur%20de%20virtualisation/spaces/Serveur%20de%20Marcoussis/spaces/choix/spaces/SGBFV/pages/WebHome?media=json</a></p>
  
  <p>But my request is going to:</p>
  
  <p><a href="http://swininducasa02.ptx.fr.sopra:8080/xwiki-enterprise-web-8.4.5/rest/wikis/xwiki/spaces/Main/spaces/PIC/spaces/Serveur%2520de%2520virtualisation/spaces/Serveur%2520de%2520Marcoussis/spaces/choix/spaces/SGBFV/pages/WebHome?media=json" rel="nofollow noreferrer">http://swininducasa02.ptx.fr.sopra:8080/xwiki-enterprise-web-8.4.5/rest/wikis/xwiki/spaces/Main/spaces/PIC/spaces/Serveur%2520de%2520virtualisation/spaces/Serveur%2520de%2520Marcoussis/spaces/choix/spaces/SGBFV/pages/WebHome?media=json</a></p>
  
  <p>The character %20 becomes %2520. I used exchange because I have to set Auth headers</p>
  
  <p>Please, can you help me?</p>