Here you can find the source of requestGet(String url)
Parameter | Description |
---|---|
url | The url of the request |
Parameter | Description |
---|---|
IOException | If something went wrong during establishing connection |
private static HttpURLConnection requestGet(String url) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class Main { /**//from ww w . j ava2s .c o m * Sets up and opens a new HttpURLConnection to perform a HTTP GET request. * One can then directly call the {@link HttpURLConnection#connect()} and * read the response code and read the response through its InputStream. * * @param url * The url of the request * @return * The setup HttpURLConnection object * @throws IOException * If something went wrong during establishing connection */ private static HttpURLConnection requestGet(String url) throws IOException { URL getUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) getUrl .openConnection(); conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod("GET"); conn.setDoInput(true); return conn; } }