Here you can find the source of getHttpUrlConnection(URL url)
Parameter | Description |
---|---|
url | the url of a HTTP resource |
Parameter | Description |
---|---|
IOException | an exception |
public static HttpURLConnection getHttpUrlConnection(URL url) throws IOException
//package com.java2s; /*/*from w w w.ja v a2s .c o m*/ * Webical - http://www.webical.org * Copyright (C) 2007 Func. Internet Integration * * This file is part of Webical. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; public class Main { /** * Returns a HttpUrlConnection for a URL pointing to an HTTP resource. Make sure it does point to a HTTP resource or a IlliagalArgumentException is thrown * @param url the url of a HTTP resource * @return a HttpUrlConnection * @throws IOException */ public static HttpURLConnection getHttpUrlConnection(URL url) throws IOException { URLConnection connection = url.openConnection(); if (connection instanceof HttpURLConnection) { return (HttpURLConnection) connection; } else { throw new IllegalArgumentException("Url is not targeted at an HTTP resource" + url); } } }