Example usage for javax.net.ssl HttpsURLConnection getInputStream

List of usage examples for javax.net.ssl HttpsURLConnection getInputStream

Introduction

In this page you can find the example usage for javax.net.ssl HttpsURLConnection getInputStream.

Prototype

public InputStream getInputStream() throws IOException 

Source Link

Document

Returns an input stream that reads from this open connection.

Usage

From source file:com.ct855.util.HttpsClientUtil.java

private static String print_content(HttpsURLConnection con) {
    if (con != null) {

        try {//from  w ww  .  ja  va2  s  . c  o  m

            System.out.println("****** Content of the URL ********");
            BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));

            String input;

            while ((input = br.readLine()) != null) {
                System.out.println(input);
            }
            br.close();
            return input;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return "";
}

From source file:Main.java

private static String getData(String target, String method, String token) {
    try {/*from   w w w .j av a2s .c o  m*/
        URL url = new URL(target);
        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

        if (!TextUtils.isEmpty(token))
            conn.setRequestProperty("Authorization", token);

        conn.setRequestMethod(method);
        conn.connect();

        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line, data = "";
        while ((line = in.readLine()) != null)
            data += line;
        in.close();

        return data;
    } catch (IOException ignored) {
        ignored.printStackTrace();
    }

    return null;
}

From source file:tk.egsf.ddns.JSON_helper.java

public static String getJsonUrl(String URL) {
    String ret = "";

    String https_url = URL;
    URL url;/*from   www  .j a  v a 2 s. co  m*/
    try {

        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            @Override
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };

        // Install the all-trusting trust manager
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        url = new URL(https_url);
        HttpsURLConnection con = (HttpsURLConnection) url.openConnection();

        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String input;
        while ((input = br.readLine()) != null) {
            ret += input;
        }
        br.close();

        System.out.println(ret);

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (ConnectException e) {
        Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, "Exgotou o tempo de resposta");
        System.out.println("");
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
    } catch (KeyManagementException ex) {
        Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException e) {
        e.printStackTrace();

    }

    return ret;
}

From source file:Main.java

private static String getData(String target, String method, String token) {
    try {//w  w w.  j ava2  s. c  o m
        URL url = new URL(target);
        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

        if (!TextUtils.isEmpty(token)) {
            conn.setRequestProperty("Authorization", token);
        }

        conn.setRequestMethod(method);
        conn.connect();

        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line, data = "";
        while ((line = in.readLine()) != null) {
            data += line;
        }
        in.close();

        return data;
    } catch (IOException ignored) {
        ignored.printStackTrace();
    }

    return null;
}

From source file:org.liberty.android.fantastischmemo.downloader.google.WorksheetFactory.java

public static List<Worksheet> getWorksheets(Spreadsheet spreadsheet, String authToken)
        throws XmlPullParserException, IOException {
    String worksheetAddress = "https://spreadsheets.google.com/feeds/worksheets/" + spreadsheet.getId()
            + "/private/full?access_token=" + authToken;
    URL url = new URL(worksheetAddress);
    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

    if (conn.getResponseCode() / 100 >= 3) {
        String s = new String(IOUtils.toByteArray(conn.getErrorStream()));
        throw new RuntimeException(s);
    }/*from   w w  w  .j a v a2  s .co  m*/
    List<Worksheet> worksheetList = EntryFactory.getEntries(Worksheet.class, conn.getInputStream());
    return worksheetList;
}

From source file:tk.egsf.ddns.JSON_helper.java

public static String getJsonUrl(String URL, String Auth) {
    String ret = "";

    String https_url = URL;
    URL url;//from   w  w  w .  j a  v a  2s .  com
    try {

        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            @Override
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };

        // Install the all-trusting trust manager
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        url = new URL(https_url);
        HttpsURLConnection con = (HttpsURLConnection) url.openConnection();

        con.setRequestProperty("Authorization", Auth);

        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String input;
        while ((input = br.readLine()) != null) {
            ret += input;
        }
        br.close();

        System.out.println(ret);

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (ConnectException e) {
        Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, "Exgotou o tempo de resposta");
        System.out.println("");
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
    } catch (KeyManagementException ex) {
        Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException e) {
        e.printStackTrace();

    }

    return ret;
}

From source file:org.liberty.android.fantastischmemo.downloader.google.SpreadsheetFactory.java

public static List<Spreadsheet> getSpreadsheets(String authToken) throws XmlPullParserException, IOException {
    URL url = new URL(
            "https://spreadsheets.google.com/feeds/spreadsheets/private/full?access_token=" + authToken);
    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    //conn.addRequestProperty("Authorization", "GoogleLogin auth=" + authToken);

    if (conn.getResponseCode() / 100 >= 3) {
        String s = new String(IOUtils.toByteArray(conn.getErrorStream()));
        throw new IOException(s);
    }//from   w ww.  ja  va  2 s .co m

    List<Spreadsheet> spreadsheetList = EntryFactory.getEntries(Spreadsheet.class, conn.getInputStream());
    return spreadsheetList;
}

From source file:org.liberty.android.fantastischmemo.downloader.google.DocumentFactory.java

public static List<Document> findDocuments(String title, String authToken) throws Exception {
    URL url = new URL("https://www.googleapis.com/drive/v2/files?q="
            + URLEncoder.encode("title = '" + title + "'", "UTF-8"));

    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.setRequestProperty("Authorization", "Bearer " + authToken);

    if (conn.getResponseCode() >= 300) {
        String s = new String(IOUtils.toByteArray(conn.getErrorStream()));
        throw new RuntimeException(s);
    }//from   www  .ja  v  a2 s .  com

    List<Document> documentList = EntryFactory.getEntriesFromDriveApi(Document.class, conn.getInputStream());
    return documentList;
}

From source file:com.camel.trainreserve.JDKHttpsClient.java

public static String doGet(String url) {
    InputStream in = null;/*www.j a  va 2s  . c o  m*/
    BufferedReader br = null;
    StringBuffer str_return = new StringBuffer();
    try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, new TrustManager[] { new DefaultTrustManager() }, new java.security.SecureRandom());
        URL console = new URL(url);
        HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
        conn.setSSLSocketFactory(sc.getSocketFactory());
        conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
        conn.connect();
        in = conn.getInputStream();
        br = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = br.readLine()) != null) {
            str_return = str_return.append(line);
        }
        conn.disconnect();
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (KeyManagementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        try {
            br.close();
            in.close();
        } catch (Exception e) {
        }
    }
    return str_return.toString();
}

From source file:org.liberty.android.fantastischmemo.downloader.google.FolderFactory.java

public static List<Folder> getFolders(String authToken) throws XmlPullParserException, IOException {
    URL url = new URL("https://www.googleapis.com/drive/v2/files?q="
            + URLEncoder.encode("mimeType = 'application/vnd.google-apps.folder'", "UTF-8"));
    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.setRequestProperty("Authorization", "Bearer " + authToken);
    if (conn.getResponseCode() / 100 >= 3) {
        String s = new String(IOUtils.toByteArray(conn.getErrorStream()));
        throw new IOException(s);
    }/*from  w ww . j  a v  a2  s  .c o  m*/

    List<Folder> folderList = EntryFactory.getEntriesFromDriveApi(Folder.class, conn.getInputStream());

    return folderList;
}