我正试图从一个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]);
}
我的回答是:TRYING2020/1/12014/04/1103
,但它应该是:
TRYING 2020/1/1 2014/04/11 0 3
你知道怎么做吗?(对不起,如果这是愚蠢的,但试图找到一个帖子,但每一个我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();
}
找到了。实际上,我认为TAB是4个空格的组合…如果用空格分割,就得到一个数组。但是使用制表符分割会得到响应