这是您可以从服务中以字符串数据的形式获取数据的方式。
public String getDataFromService()
{
try {
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(yourserviceURLgoeshere);
HttpResponse httpResponse=httpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
is=entity.getContent();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return parseExecutedRequest();
}
private String parseExecutedRequest()
{
try {
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder stringBuilder=new StringBuilder();
String line=null;
while((line=bufferedReader.readLine())!=null)
{
stringBuilder.append(line+ "\n");
}
is.close();
result=stringBuilder.toString();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}