Java URL Download get(String urlStr)

Here you can find the source of get(String urlStr)

Description

get

License

Open Source License

Declaration

public static String get(String urlStr) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static String get(String urlStr) {
        try {/* w w w . j a v a 2s . c  o  m*/
            URL url = new URL(urlStr);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            connection.setRequestMethod("GET");
            connection.setInstanceFollowRedirects(true);

            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            List<String> lines = in.lines().collect(Collectors.toList());

            in.close();

            return String.join("\n", lines);
        } catch (IOException e) {
            return null;
        }
    }
}

Related

  1. get(String url)
  2. get(String url, int timeout, Map header)
  3. get(String url, Map headers)
  4. get(String url, Map params)
  5. get(String url, String encoding)
  6. get(String urlString)
  7. get(URL host, String endpoint, String customer, String name, String version, OutputStream out)
  8. get(URL url)
  9. get(URL url, String acceptType)