0

I am using Volley Library in my project.

I am using ImageLoader to load & display image from https url.

for example:

ImageLoader mImageLoader;
ImageView mImageView;
// The URL for the image that is being loaded.
private static final String IMAGE_URL =
    "https://developer.android.com/images/training/system-ui.png";
...
mImageView = (ImageView) findViewById(R.id.regularImageView);

// Get the ImageLoader through your singleton class.
mImageLoader = MySingleton.getInstance(this).getImageLoader();
mImageLoader.get(IMAGE_URL, ImageLoader.getImageListener(mImageView,
         R.drawable.def_image, R.drawable.err_image));

It loads some images successfully but not all.

For some images I got below error response:

BasicNetwork.performRequest: Unexpected response code 403 for https://developer.android.com/images/training/system-ui.png

Any solution to resolve this issue ?

Priyank Patel
  • 12,244
  • 8
  • 65
  • 85
  • Post full Logcat error. Try to download other image (simple HTTP protocol). – dieter_h Sep 12 '15 at 06:07
  • It's volley library error. So, it gives me only this one line error in logcat. – Priyank Patel Sep 12 '15 at 06:12
  • IMO, sometimes, BasicNetwork catched exception but onResponse still called, you can see [the screenshot (last line) at my answer here](http://stackoverflow.com/questions/32478222/com-android-volley-noconnectionerror-java-net-protocolexception-unexpected-sta/32482509#32482509) – BNK Sep 12 '15 at 06:24

3 Answers3

0

I have tried your code but it seems working fine for me.

Method to send ImageRequest :

 private void sendImageRequest() {
        final String IMAGE_URL =
                "https://developer.android.com/images/training/system-ui.png";
        ImageRequest request = new ImageRequest(IMAGE_URL,
                new Response.Listener<Bitmap>() {
                    @Override
                    public void onResponse(Bitmap bitmap) {
                        Log.e("Image Sucess", bitmap.toString());
//                        mImageView.setImageBitmap(bitmap);
                        imageView.setImageBitmap(bitmap);
                    }
                }, 0, 0, null,
                new Response.ErrorListener() {
                    public void onErrorResponse(VolleyError error) {
                        Log.e("Image Error", error.getMessage());
//                        mImageView.setImageResource(R.drawable.image_load_error);
                    }
                });
// Access the RequestQueue through your singleton class.
        Volley.newRequestQueue(getApplicationContext()).add(request);
    }

library in gradle :

  compile 'com.mcxiaoke.volley:library:1.0.19'

And Internet permission in Manifest.xml

 <uses-permission android:name="android.permission.INTERNET" />

Try with this code please.

Thanks.

AndiGeeky
  • 11,266
  • 6
  • 50
  • 66
0

Together with my comments above at your question, you can find more in BasicNetwork.java:

...
               } catch (IOException e) {
                    int statusCode = 0;
                    NetworkResponse networkResponse = null;
                    if (httpResponse != null) {
                        statusCode = httpResponse.getStatusLine().getStatusCode();
                    } else {
                        throw new NoConnectionError(e);
                    }
                    VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl());
                    if (responseContents != null) {
                        networkResponse = new NetworkResponse(statusCode, responseContents,
                                responseHeaders, false, SystemClock.elapsedRealtime() - requestStart);
                        if (statusCode == HttpStatus.SC_UNAUTHORIZED ||
                                statusCode == HttpStatus.SC_FORBIDDEN) {
                            attemptRetryOnException("auth",
                                    request, new AuthFailureError(networkResponse));
                        } else {
                            // TODO: Only throw ServerError for 5xx status codes.
                            throw new ServerError(networkResponse);
                        }
                    } else {
                        throw new NetworkError(networkResponse);
                    }
                }

If the response code is 403 - FORBIDDEN, attemptRetryOnException() will be called and you will get the image.

Hope this helps!

BNK
  • 23,994
  • 8
  • 77
  • 87
0

It was not Volley or ImageLoader fault.

Actually I am trying to access an image of amazon s3 bucket using the bucket url directly.

Though, image doesn't exist at that url, S3 returns a 403 instead of a 404 when the user doesn't have permission to access it.

Solved by this answer, check it for more details

Community
  • 1
  • 1
Priyank Patel
  • 12,244
  • 8
  • 65
  • 85