Url出现非法参数异常

访问网址出现:illegal character in scheme at index x

使用get方式请求数据,参数在url后。

开始以为是字符编码问题,当都用utf-8之后发现没用,然后有些手机不会报错,有些手机会;

 public static void getRemoteJsonContent(final Map<String, String> param, final String url, final XValueCallback<String> callBack) throws Exception {
        String tempUrl = url;
        String jsonResult = "";
        //post请求返回结果
        DefaultHttpClient httpClient = new DefaultHttpClient();
        String paramStr = "";
        if (param != null) {
            for (String key : param.keySet()) {
//                paramStr += URLEncoder.encode(key, "UTF-8") + "=" + URLEncoder.encode(param.get(key), "UTF-8") + "&";
                paramStr += key + "=" + param.get(key) + "&";
            }
            if (!TextUtils.isEmpty(paramStr)) {
                tempUrl += "?" + paramStr;
            }
        }
        HttpGet method = new HttpGet(tempUrl.trim());
        HttpResponse result = httpClient.execute(method);
        /**请求发送成功,并得到响应**/
        if (result.getStatusLine().getStatusCode() == 200) {
            /**读取服务器返回过来的json字符串数据**/
            jsonResult = EntityUtils.toString(result.getEntity(), "UTF-8");
            callBack.onSuccess(jsonResult);

        }

    }

在这里url是

 String url = " http://testurl/xaeo/App/Api/app.php?name=13415654215&password=123456";

仔细看,才发现这里面有一个非法字符就是最开始有一个空格;去掉空格就没事了。

猜你喜欢

转载自zhonglunshun.iteye.com/blog/2273903