Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with URL in Java
    text
    copied!<p>I'm working on an application that plots map route based on inputs. Here's a sample input URI:-</p> <pre><code>http://maps.googleapis.com/maps/api/directions/json?origin=38.842794,-77.408132&amp;destination=38.8685938,-77.2711787&amp;region=en&amp;sensor=true&amp;waypoints=optimize:true|38.839619,-77.410309 </code></pre> <p>Using httpget,httpresponse I plan to get the response from the URI in json. I'm having an issue with this link. </p> <pre><code>HttpGet httpget = new HttpGet(uri); HttpResponse response; try { response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if(entity!=null) { InputStream instream = entity.getContent(); StreamToString st = new StreamToString(); result = st.convertStreamtoString(instream); blah blah blah ... </code></pre> <p>I'm getting an error saying:-</p> <pre><code>Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 160: http://maps.googleapis.com/maps/api/directions/json?origin=38.842794,-77.408132&amp;destination=38.8685938,-77.2711787&amp;region=en&amp;sensor=true&amp;waypoints=optimize:true|38.839619,-77.410309 </code></pre> <p>So I thought it might have occurred since I did not encode the URI. So later I tried using </p> <pre><code>uri = URLEncoder.encode(uri, "UTF-8"); </code></pre> <p>Then I've been getting a different error saying:-</p> <pre><code>java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=http://maps.googleapis.com/maps/api/directions/json?origin=38.842794,-77.408132&amp;destination=38.8685938,-77.2711787&amp;region=en&amp;sensor=true&amp;waypoints=optimize:true|38.839619,-77.410309 </code></pre> <p>Please help me in resolving this issue. Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload