Get an object of HttpURLConnection. - Android Network

Android examples for Network:HTTP Get

Description

Get an object of HttpURLConnection.

Demo Code


//package com.java2s;

import java.io.IOException;

import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    /**//from   w  ww . j  av a  2 s .c o m
     * Get an object of HttpURLConnection.
     * 
     * @param resourceURL
     *            The resource URL.
     * @return
     * @throws IOException
     */
    private static HttpURLConnection getHttpURLConnectionByGET(
            String resourceURL) throws IOException {
        HttpURLConnection conn = null;
        if (null != resourceURL && !"".equals(resourceURL.trim())) {
            URL url = new URL(resourceURL);
            conn = (HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(5000);
            conn.setRequestMethod("GET");
        }
        return conn;
    }
}

Related Tutorials