0
的回報,我有其中有POST方法reuturn String作爲響應彈簧安置服務Android的REST服務調用彈簧安置後期服務的方法,串
我怎樣才能趕上從Android的休息客戶爲例返回的字符串
請幫忙..!
的回報,我有其中有POST方法reuturn String作爲響應彈簧安置服務Android的REST服務調用彈簧安置後期服務的方法,串
我怎樣才能趕上從Android的休息客戶爲例返回的字符串
請幫忙..!
在你休息的客戶,你應該有這樣的事情:
HttpEntity entity = httpResponse.getEntity();
if (entity != null)
{
InputStream instream = entity.getContent();
response = convertStreamToString(instream);
// Closing the input stream will trigger connection release
instream.close();
}
並從流轉換爲字符串會是這樣的方法:
private static String convertStreamToString(InputStream is)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try
{
while ((line = reader.readLine()) != null)
{
sb.append(line);
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return sb.toString();
}