开发者

Error while downloading images from a server

I am getting this error from the logcat

org.apache.http.NoHttpResponseException: The target server failed to respond.

What might be the reason?

My download code 开发者_运维问答is as below.

HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse)httpclient.execute(httpRequest);

HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream instream = bufHttpEntity.getContent();
bmImg = BitmapFactory.decodeStream(instream);


call following methods and pass in URL .

public Bitmap DownloadFromUrl(String imageURL) { //this is the downloader method

        Bitmap bm=null;
            try {
                    URL url = new URL(imageURL); //you can write here any link



                   URLConnection ucon = url.openConnection();


                  InputStream is = ucon.getInputStream();
                   BufferedInputStream bis = new BufferedInputStream(is);


                    ByteArrayBuffer baf = new ByteArrayBuffer(50);
                   int current = 0;
                   while ((current = bis.read()) != -1) {
                            baf.append((byte) current);
                   }

                  bm= BitmapFactory.decodeByteArray(baf.toByteArray(), 0, baf.toByteArray().length);


          } catch (IOException e) {
                    Log.d("ImageManager", "Error: " + e);
          }
            return bm;

    }


NoHttpResponseException means one and only thing: the server closed connection without sending back an HTTP response message, most likely due to an abnormal condition encountered during processing of the request. In other words, this is most likely a server side bug.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜