Here you can find the source of createHttpURLConnection(String urlString, int timeout)
Parameter | Description |
---|---|
urlString | a parameter |
timeout | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static HttpURLConnection createHttpURLConnection(String urlString, int timeout) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w.j a va2 s. c om*/ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation ******************************************************************************/ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; public class Main { /** * Create an HTTP connection (GET). Returns null if the URL does not use HTTP(S) protocol. * @param urlString * @param timeout * @return * @throws IOException */ public static HttpURLConnection createHttpURLConnection(String urlString, int timeout) throws IOException { URL url = new URL(urlString); URLConnection connetion = url.openConnection(); HttpURLConnection httpConnection = null; if (connetion instanceof HttpURLConnection) { httpConnection = (HttpURLConnection) url.openConnection(); httpConnection.setInstanceFollowRedirects(true); httpConnection.setRequestMethod("GET"); httpConnection.setConnectTimeout(timeout); } return httpConnection; } }