2

最初のリクエストで、インターネットにアクセスしてデータを取得します。もう一度試してみると、すでに入力ストリームにあるデータが返されます。キャッシュされたデータをクリアして、毎回新しいリクエストを行うにはどうすればよいですか?

これは私のコードです:

InputStreamReader in = null;
in = new InputStreamReader(url.openStream());
response = readFully(in);
url.openStream().close();
4

3 に答える 3

0

毎回 URL オブジェクトを再作成します。

于 2012-06-10T23:16:01.483 に答える
0

HttpClient API が役に立つかもしれません

address = "http://google.com"
String html = "";
HttpClient httpClient = DefaultHttpClient();
HttpGet httpget = new HttpGet(address);
BufferedReader in = null;
HttpResponse response = null;
response = httpClient.execute(httpget);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.seperator");
while ((l = in.readLine()) != null) {
    sb.append(l + nl);
}
in.close();
html = sb.toString();

いくつかの例外をキャッチする必要があります

于 2012-06-10T23:34:36.413 に答える
0

URLConnection を作成して、キャッシュ ポリシーを明示的に設定できます。

final URLConnection conn = (URLConnection)url.openConnection();
conn.setUseCaches(false); // Don't use a cached copy.
InputStream in = new BufferedInputStream(urlConnection.getInputStream());

詳細については、Android URLConnection のドキュメントを参照してください。

于 2012-06-10T23:27:19.703 に答える