集册 Java实例教程 做Https获取

做Https获取

欢马劈雪     最近更新时间:2020-01-02 10:19:05

560
做Https获取


//package com.nowjava;

import java.io.BufferedReader;

/*
NowJava.com - 时代Java 提 供
*/

import java.io.IOException;

import java.io.InputStreamReader;


import java.net.MalformedURLException;

import java.net.URL;


import javax.net.ssl.HttpsURLConnection;


public class Main {

    public static void main(String[] argv) throws Exception {

        String url = "nowjava.com";

        System.out.println(doHttpsGet(url));

    }


    public static String doHttpsGet(String url)

            throws MalformedURLException, IOException {

        // establish connection and send request

        HttpsURLConnection connection = (HttpsURLConnection) new URL(url)//来自 时代Java公众号 - N o w J a  v a . c o m

                .openConnection();

        connection.setRequestMethod("GET");

        connection.setDoOutput(false);

        connection.setDoInput(true);


        // read response

        BufferedReader reader = new BufferedReader(new InputStreamReader(

展开阅读全文