Java HTTP Port Find get(int port, String applicationRoot, String resource, String path)

Here you can find the source of get(int port, String applicationRoot, String resource, String path)

Description

get

License

Open Source License

Declaration

public static String get(int port, String applicationRoot, String resource, String path) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static String get(int port, String applicationRoot, String resource, String path) throws Exception {
        String url = "http://localhost:" + port + applicationRoot + resource + path;

        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

        con.setRequestMethod("GET");

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line;/*  w  ww  . j a v a2s .  co  m*/
        StringBuilder response = new StringBuilder();

        while ((line = in.readLine()) != null) {
            response.append(line);
        }

        in.close();
        return response.toString();
    }
}

Related

  1. findUnusedPorts(int numPorts)
  2. freePort()
  3. freePort()
  4. freePort()
  5. freePort(int suggestedPort)
  6. getAllHostNames(String hostName, int portNumber, String bindingUser)
  7. getAnonymousPort()
  8. getAnonymousPort()
  9. getAvailableListenPort()