Here you can find the source of getResponse(String name, String host, int port)
public static String getResponse(String name, String host, int port) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2007 Red Hat, Inc. //from ww w.j a v a2s. c om * 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: * Red Hat, Inc. - initial API and implementation ******************************************************************************/ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import java.net.HttpURLConnection; import java.net.URL; public class Main { private static final int RESPONSE_TIMEOUT = 10 * 1024; public static String getResponse(String name, String host, int port) throws IOException { URL url = new URL("http://" + host + ":" + port + "/" + name); HttpURLConnection connection = connect(url); return toString(new BufferedInputStream(connection.getInputStream())); } private static HttpURLConnection connect(URL url) throws IOException { HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setUseCaches(false); connection.setDoInput(true); connection.setAllowUserInteraction(false); connection.setConnectTimeout(RESPONSE_TIMEOUT); connection.setInstanceFollowRedirects(true); connection.setDoOutput(false); return connection; } public static String toString(InputStream in) throws IOException { StringWriter writer = new StringWriter(); for (int data = -1; ((data = in.read()) != -1);) { writer.write(data); } return writer.toString(); } }