I'm working on an application that plots map route based on inputs. Here's a sample input URI:-
http://maps.googleapis.com/maps/api/directions/json?origin=38.842794,-77.408132&destination=38.8685938,-77.2711787®ion=en&sensor=true&waypoints=optimize:true|38.839619,-77.410309
Using httpget,httpresponse I plan to get the response from the URI in json. I'm having an issue with this link.
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 ...
I'm getting an error saying:-
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&destination=38.8685938,-77.2711787®ion=en&sensor=true&waypoints=optimize:true|38.839619,-77.410309
So I thought it might have occurred since I did not encode the URI. So later I tried using
uri = URLEncoder.encode(uri, "UTF-8");
Then I've been getting a different error saying:-
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&destination=38.8685938,-77.2711787®ion=en&sensor=true&waypoints=optimize:true|38.839619,-77.410309
Please help me in resolving this issue. Thanks in advance.