【问题标题】:Error in http connection java.lang.IllegalArgumentException: Illegal character in query at index 76http 连接 java.lang.IllegalArgumentException 中的错误:索引 76 处的查询中存在非法字符
【发布时间】:2014-08-30 01:13:54
【问题描述】:

我在 http 连接 java.lang.IllegalArgumentException: Illegal character in query at index 76 中遇到错误。 尝试了所有 3 个示例。无法修复它。尝试了 url_encode,但它没有考虑组件:locality 部分。如何使这个 url 工作。提前致谢。

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>();

还有

                            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>();

还有

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;

【问题讨论】:

    标签: java android uri http-get


    【解决方案1】:

    76 处的字符是|,这可能是问题的原因。您是否尝试将其替换为十六进制格式%7C,形成:http://maps.googleapis.com/maps/api/geocode/json?components=locality:Spokane%7Ccountry=us%7Cadministrative_area:washington&amp;address="+newText+"&amp;sensor=false

    另外,newText 定义了吗?

    【讨论】:

      猜你喜欢
      • 2015-01-23
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2015-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多