Here you can find the source of get(String url)
Parameter | Description |
---|---|
url | url to send request to (including all arguments etc). |
public static String get(String url)
//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; public class Main { private static final String USER_AGENT = "Mozilla/4.76"; /**/*w w w .j ava 2s . c om*/ * Run a (blocking) HTTP get request. * * @param url url to send request to (including all arguments etc). * @return Response, empty if an exception is thrown, won't be null. */ public static String get(String url) { String result = ""; try { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setInstanceFollowRedirects(true); connection.setRequestMethod("GET"); connection.setRequestProperty("User-Agent", USER_AGENT); connection.setConnectTimeout(3000); connection.setReadTimeout(10000); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder builder = new StringBuilder(); String line; while ((line = in.readLine()) != null) { builder.append(line); } in.close(); result = builder.toString(); } catch (IOException ignored) { } return result; } }