さまざまなデバイスでさまざまなビットマップをダウンロードするために httpclient (apache クレデンシャル) 接続を使用すると失敗します.... 1 つでも問題なく動作します。なぜですか?
接続を適切に閉じていますか?私はそれについて確信が持てません。私はこれらの種類の資格情報 http 接続を見つめています。
サーバーに接続して50個のビットマップをダウンロードするAndroid(Java)用のアプリを開発しています。毎回この関数を使用して各ビットマップをダウンロードしています:
public static Bitmap getRemoteBitmap(String url) {
Bitmap bm=null;
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
try {
((AbstractHttpClient) httpclient).getCredentialsProvider().setCredentials(
new org.apache.http.auth.AuthScope(null,-1),
new org.apache.http.auth.UsernamePasswordCredentials(MagazineStatus._username, MagazineStatus._password));
response = httpclient.execute(new HttpGet(url));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK) {
try {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
bm=BitmapFactory.decodeStream(content );
}catch(Exception ex) {Log.e("DBF Error",ex.toString());}
}else {
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
}catch(ClientProtocolException cpe) {
Log.e("ClientProtocolException @ at FPT",cpe.toString());
} catch(Exception ex) {
Log.e("Exception at FETCHPROJECTASK",ex.toString());
}
return bm;
}
1 つのデバイスでビットマップをダウンロードしようとすると正常に動作しますが、同時に 3 つまたは 4 つのデバイスでビットマップをダウンロードしようとすると、この行bm=BitmapFactory.decodeStream(content );
で null ビットマップが返されるため、この機能で何かが失敗します。 、 、およびがnullではないためcontent
、理由がわかりません。entity
statusLine
response
bm
ビットマップが nullの場合のこれらの変数の値は次のとおりです。
応答:
"response" (id=830078599368)
entity BasicManagedEntity (id=830078617768)
headergroup HeaderGroup (id=830078599408)
locale Locale (id=830078292336)
params ClientParamsStack (id=830079041944)
reasonCatalog EnglishReasonPhraseCatalog (id=830004685872)
statusline BasicStatusLine (id=830078599344)
ステータス行:
"statusLine" (id=830078599344)
protoVersion HttpVersion (id=830004713800)
reasonPhrase "OK" (id=830078599288)
statusCode 200
実在物:
"entity" (id=830078617768)
attemptReuse false
managedConn null
wrappedEntity BasicHttpEntity (id=830078612272)
コンテンツ:
"content" (id=830078617792)
skipBuf null
eofWatcher BasicManagedEntity (id=830078617768)
selfClosed false
私は何か間違ったことをしていますか?接続は適切に閉じられていますか? これは改善できますか?どんな助けも高く評価されます。
ありがとう
編集:
接続を閉じる適切な方法は、このコードを追加することですか?
content.close();
entity.consumeContent();
または、さらに何かを追加する必要がありますか?
ありがとう