Error in http connection java.lang.IllegalArgumentException: Invalid character in request at index 76
I am getting an error on the http connection java.lang.IllegalArgumentException: Invalid character in request at index 76. Tried all 3 examples. You can fix this. Tried url_encode but it didn't accept components: localization part. How to make this url. 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;
source to share
The character at 76 is |
, which may be the cause of the problem. Have you tried replacing it with hexadecimal format %7C
by forming this http://maps.googleapis.com/maps/api/geocode/json?components=locality:Spokane%7Ccountry=us%7Cadministrative_area:washington&address="+newText+"&sensor=false
:?
It is also determined newText
?
source to share