Here you can find the source of executeHttpCommand(String host, int port, String request, String charset)
public static String executeHttpCommand(String host, int port, String request, String charset) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.Socket; import java.util.Objects; public class Main { /**// w w w. j a v a 2s.com Connect to given host:port via direct TCP socket, send the input string, and return the result (if any) as a string */ public static String executeHttpCommand(String host, int port, String request) throws Exception { return executeHttpCommand(host, port, request, "UTF-8"); } /** Connect to given host:port via direct TCP socket, send the input string, and return the result (if any) as a string */ public static String executeHttpCommand(String host, int port, String request, String charset) throws Exception { Objects.requireNonNull(host); Objects.requireNonNull(request); try (Socket socket = new Socket(host, port)) { socket.getOutputStream().write(request.getBytes(charset)); socket.shutdownOutput(); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(), charset)); String response = ""; String line = in.readLine(); while (line != null) { response += line + "\n"; line = in.readLine(); } return response; } } }