private static String QueryImds()

in imdssample.java [116:143]


    private static String QueryImds(String path, String apiVersion, String otherParams)
    {
        String imdsUrl = path + "?api-version=" + apiVersion;
        if(otherParams != null && !otherParams.isEmpty())
        {
            imdsUrl += "&" + otherParams;
        }
        
        try
        {
            URL url = new URL(imdsUrl);
            HttpURLConnection con = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
            con.setRequestMethod("GET");
            con.setRequestProperty("Metadata", "True");
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String line;
            StringBuffer response = new StringBuffer();
            while ((line = in.readLine()) != null) {
              response.append(line);
            }
            in.close();
            return response.toString();
        }
        catch(Exception ex)
        {
            return "";
        }
    }