I am getting an error in http connection java.lang.IllegalArgumentException: Illegal character in query at index 76. Tried all the 3 examples.Unable to fix it .Tried url_encode but its not taking the components:locality part into consideration.How do I make this url work .Thanks in Advance.
BufferedReader in = null;
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet();
URI website = new URI("http://maps.googleapis.com/maps/api/geocode/json?components=locality:Spokane|country=us|administrative_area:washington&address="+newText+"&sensor=false");
request.setURI(website);
HttpResponse response = httpclient.execute(request);
in = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line = in.readLine();
data = line;
suggest = new ArrayList<String>();
And
String uri =("http://maps.googleapis.com/maps/api/geocode/json?components=locality:Spokane|country=us|administrative_area:washington&address="+newText+"&sensor=false");
uri=URLEncoder.encode(uri,"UTF-8");
HttpClient hClient = new DefaultHttpClient();
HttpGet hGet = new HttpGet(uri);
ResponseHandler<String> rHandler = new BasicResponseHandler();
data = hClient.execute(hGet,rHandler);
suggest = new ArrayList<String>();
And
String urlstr="http://maps.googleapis.com/maps/api/geocode/json?";
String str_parameters = "components=locality:Spokane|country=us|administrative_area:washington";
String encodedparams = URLEncoder.encode(str_parameters,"UTF-8")+"&address="+URLEncoder.encode(newText, "UTF-8")+"&sensor="+URLEncoder.encode("false", "UTF-8");
String str_finalurl=urlstr+encodedparams;
The character at 76 is |
, which might be the cause of the issue. Have you tried replacing it with the hexadecimal format %7C
, forming this: http://maps.googleapis.com/maps/api/geocode/json?components=locality:Spokane%7Ccountry=us%7Cadministrative_area:washington&address="+newText+"&sensor=false
?
Also, is newText
defined?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.