Search code examples
javaurlpostgetadobe

Call large URL in Java


How should I call a large URL in Java? I'm integrating scene7 image server with java application. Here I call a URL of around 10000 characters which should return me an Image. What ways can I do this?

The way I wrote is -

URL oURL= new URL("<*LONG LONG URL - approx. 10k characters*>");
HttpURLConnection connection = (HttpURLConnection) oURL.openConnection();
InputStream stream = connection.getInputStream();
int len;
byte[] buf = new byte[1024];
BufferedImage bi = ImageIO.read(stream);
ImageIO.write(bi,"png",response.getOutputStream());  

while ((len = stream.read(buf)) > 0) {
    outs.write(buf, 0, len);
}

Solution

  • You won't get URLs that long to work reliably. The longest you can rely on working is around 2000 characters. Beyond that, you are liable to run into browser or server-side limits. (Or even limits in intermediate proxy servers)

    You are going to need to "think outside the box". For example:

    • pass some the information that is currently encoded in your URL in the form of POST data,
    • pass some the information in the form of custom request headers (ewww!!), or
    • come up with a clever way to encode (or compress) the informational part of the URL.

    All of these are likely to require changes to the server side.

    Reference: