Here you can find the source of sendGetRequest(String requestURL)
Parameter | Description |
---|---|
requestURL | the URL of the remote server |
Parameter | Description |
---|---|
IOException | thrown if any I/O error occurred |
public static HttpURLConnection sendGetRequest(String requestURL) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class Main { /**/*from w w w . j a va 2 s . c o m*/ * Represents an HTTP connection */ private static HttpURLConnection httpConn; /** * Makes an HTTP request using GET method to the specified URL. * * @param requestURL * the URL of the remote server * @return An HttpURLConnection object * @throws IOException * thrown if any I/O error occurred */ public static HttpURLConnection sendGetRequest(String requestURL) throws IOException { URL url = new URL(requestURL); httpConn = (HttpURLConnection) url.openConnection(); httpConn.setUseCaches(false); httpConn.setDoInput(true); // true if we want to read server's response httpConn.setDoOutput(false); // false indicates this is a GET request return httpConn; } }