Java http连接

use*_*101 16 java https http

我想设置一个http连接来发送请求并在一个独立的java应用程序中获取响应,任何人都可以帮助我如何继续这个????

Mik*_*e G 16

HttpURLConnection connection = null;
    try {
        URL url = new URL("www.google.com");
        connection = (HttpURLConnection) url.openConnection();
        connection.connect();
        connection.getInputStream();
                    // do something with the input stream here

    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    } finally {
        if(null != connection) { connection.disconnect(); }
    }
Run Code Online (Sandbox Code Playgroud)