Comment définir X-Api-Clés dans l'en-tête de requête HTTP get

Comment puis-je mettre un x-api-clé avec le apikey dans l'en-tête d'une requête HTTP get. J'ai essayé quelque chose mais il semble que cela ne fonctionne pas.
Voici mon code:

    private static String download(String theUrl)
    {
        try {
            URL url = new URL(theUrl);

            URLConnection ucon = url.openConnection();

            ucon.addRequestProperty("x-api-key", apiKey);

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

            ByteArrayBuffer baf = new ByteArrayBuffer(50);

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

            return new String (baf.toByteArray());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

EDIT:
Modifié le code avec la réponse ci-dessous, mais toujours un message d'erreur: il ne pouvait pas instancier le type HttpURLConnection(url). J'ai changé, mais maintenant, je dois remplacer les 3 méthodes (ci-dessous)

private static String download(String theUrl)
    {
        try {
            URL url = new URL(theUrl);

            URLConnection ucon = new HttpURLConnection(url) {

                @Override
                public void connect() throws IOException {
                    //TODO Auto-generated method stub

                }

                @Override
                public boolean usingProxy() {
                    //TODO Auto-generated method stub
                    return false;
                }

                @Override
                public void disconnect() {
                    //TODO Auto-generated method stub

                }
            };
            ucon.addRequestProperty("x-api-key", apiKey);
            ucon.connect();

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

            ByteArrayBuffer baf = new ByteArrayBuffer(50);

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

            return new String (baf.toByteArray());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

OriginalL'auteur Timmeeh93 | 2014-10-24