Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android从url获取带有空格的响应_Android_Url_Whitespace_Httpresponse - Fatal编程技术网

android从url获取带有空格的响应

android从url获取带有空格的响应,android,url,whitespace,httpresponse,Android,Url,Whitespace,Httpresponse,我试图从一个url获得响应,就像它是(包括空格)但空格总是被删除。这是我的密码 HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(link); HttpResponse httpResponse; httpResponse = httpClient.execute(httpGet); Http

我试图从一个url获得响应,就像它是(包括空格)但空格总是被删除。这是我的密码

HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(link); 
            HttpResponse httpResponse;
            httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();       

            String  s = EntityUtils.toString(httpEntity, HTTP.UTF_8);

            String[] ar = s.split(" ");
            Log.e("responsesize" , String.valueOf(ar.length));
            for(int i =0 ; i < ar.length ; ++i)
            {
                Log.e("response" , ar[i]);
            }
你知道怎么做吗? (sry如果这很愚蠢,但试图在上面找到帖子,但evthg i c正在从url中删除空白,而不是阻止回复)

试试这种方法

try{

                StringBuffer sb = new StringBuffer();
                URL url = new URL(location);
                urlConnection = (HttpURLConnection) url.openConnection();

                BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    sb.append(line + "\n");
                }
                return sb.toString();
            }  
    finally {
                urlConnection.disconnect();
            }

找到了。实际上,我认为标签是4个空格的组合。。。所以,如果我用空格拆分,我会得到一个数组。但是用制表符拆分会给我你从服务器得到的响应??嗯,如果你用
split()
字符串
(空格),那么所有的空格都会消失……找到它了。。。实际上,我认为标签是4个空格的组合。。。所以如果我用空格分割,我得到一个数组。。但是用标签拆分会给我一个回应。。。但tab键不是等于4个空格吗?按tab键时,代码编辑器通常使用4个空格。但tab实际上是一个与空格不同的字符。
try{

                StringBuffer sb = new StringBuffer();
                URL url = new URL(location);
                urlConnection = (HttpURLConnection) url.openConnection();

                BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    sb.append(line + "\n");
                }
                return sb.toString();
            }  
    finally {
                urlConnection.disconnect();
            }