title: URISyntaxException - How to deal with urls with %
body: <p>I am fairly new to Java and came across this issue. I tried searching but never got a correct answer.</p>
  
  <p>I have a string for example </p>
  
  <pre><code>String name = anything 10%-20% 04-03-07
  </code></pre>
  
  <p>Now I need to build up a url string with this String name like below.</p>
  
  <pre><code>http://something.com/test/anything 10%-20% 04-03-07
  </code></pre>
  
  <p>I tried replacing the spaces with %20 and now I am getting the new url as </p>
  
  <pre><code>http://something.com/test/anything%2010%-20%%2004-03-07
  </code></pre>
  
  <p>When I use this url and fire it in firefox it just works fine but while processing in Java it is apparently throwing </p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException
  at java.net.URI.create(Unknown Source)
  at org.apache.http.client.methods.HttpGet.&lt;init&gt;(HttpGet.java:69)
  Caused by: java.net.URISyntaxException: Malformed escape pair at index 39 : 
  at java.net.URI$Parser.fail(Unknown Source)
  at java.net.URI$Parser.scanEscape(Unknown Source)
  at java.net.URI$Parser.scan(Unknown Source)
  at java.net.URI$Parser.checkChars(Unknown Source)
  at java.net.URI$Parser.parseHierarchical(Unknown Source)
  at java.net.URI$Parser.parse(Unknown Source)
  at java.net.URI.&lt;init&gt;(Unknown Source)
  ... 6 more
  </code></pre>
  
  <p>This is the code throwing error</p>
  
  <pre><code>HttpClient httpclient = new DefaultHttpClient();
  HttpGet httpget = new HttpGet(url);
  HttpResponse response = httpclient.execute(httpget);
  </code></pre>