Getting Image from URL (Java)

前端 未结 6 2080
长发绾君心
长发绾君心 2020-12-10 01:09

I am trying to read the following image

\"enter

But it is showing IIOException

6条回答
  •  醉酒成梦
    2020-12-10 01:51

    You are getting an HTTP 400 (Bad Request) error because there is a space in your URL. If you fix it (before the zoom parameter), you will get an HTTP 400 error (Unauthorized). Maybe you need some HTTP header to identify your download as a recognised browser (use the "User-Agent" header) or additional authentication parameter.

    For the User-Agent example, then use the ImageIO.read(InputStream) using the connection inputstream:

    URLConnection connection = url.openConnection();
    connection.setRequestProperty("User-Agent", "xxxxxx");
    

    Use whatever needed for xxxxxx

提交回复
热议问题