【发布时间】:2014-01-06 14:20:10
【问题描述】:
以下是我用来通过传递检索到 json 对象的 url 从服务器读取响应的方法。
有一个非常特殊的问题,即旧值仍然被获取,尽管数据已经更新。
我试图找出它的解决方案,但仍然没有成功。
网址类型:http://www.mywebsite.com/svc/user_auth/user_id
其中用户 id 是作为参数传递的用户的唯一整数 id。
public static String getResponse(String url){
String downloadedData = null;
Log.e("getResponse", url);
try {
URL downloadURL = new URL(url);
InputStream inputStream = (InputStream) downloadURL.getContent();
if (null != inputStream) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[512];
int readCounter = inputStream.read(buffer);
while (readCounter != -1) {
byteArrayOutputStream.write(buffer, 0, readCounter);
readCounter = inputStream.read(buffer);
}
downloadedData = new String(
byteArrayOutputStream.toByteArray());
/*if (null != downloadedData && !"".equals(downloadedData)) {
downloadedJson = new JSONObject(downloadedData);
}*/
}else{
Log.e("getResponse", "Response is null");
}
} catch (Exception e) {
e.printStackTrace();
}
return downloadedData;
}
任何帮助将不胜感激。
【问题讨论】:
标签: android web-services http-get