これは、文字列データの形式でサービスからデータを取得する方法です。
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;
}