首页 > 代码库 > 安卓必备,HttpUrlConnection

安卓必备,HttpUrlConnection

package aaa;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class aaa {

    public static void main(String[] args) throws IOException {
        URL url = new URL("https://123.sogou.com/");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        StringBuilder build = new StringBuilder();
        BufferedReader read = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String s;
        while ((s = read.readLine()) != null) {
            build.append(s + "\n");
        }
        String html=build.toString();
    }
}

 

安卓必备,HttpUrlConnection