0

I am trying to download an image from Java code. My code is already working fine for tons of other images, but this one refuses to download.

I'm sure the image exists and I am able to view it inside the browser: http://lemonde-emploi.blog.lemonde.fr/files/2017/02/La-Ru%C3%A9e-des-licornes-Hazard.jpg

I'm using Play framework WS Scala client to download the image. It's just a wrapper around Java famous AsyncHttpClient with a Netty implementation.

I'm running the following code, which work fine for many other images, but fails just for this one:

    WS
      .url(url)
      .withQueryString(queryString: _*)
      .withHeaders("User-Agent" -> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36")
      .get

I've set exactly the same User-Agent as my local browser which succeed to access the image.

Here's the server response in debug: it returns a 400 status code.

response

Any idea why it happens?

Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
  • very strange, try to download image with wget, and in code with fluent-hc, it works fine. m.b problem in WS client? Do you try to download image directly by using AsyncHttpClient ? – kurt Mar 10 '17 at 13:55

1 Answers1

0

The legacy "com.ning" package in your image shows that you're still running AHC1, that has reached end-of-life and I no longer maintain.

You're most likely hitting an old AHC bug related to URL encoding that's been long fixed (I checked that modern releases of AHC2 work fine with your URL).

Basically, it's time to consider upgrading Play/AHC versions.

Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29