Java URL Parameter Builder sendGetRequest(String path, Map params, String enc)

Here you can find the source of sendGetRequest(String path, Map params, String enc)

Description

send Get Request

License

Apache License

Declaration

public static boolean sendGetRequest(String path, Map<String, String> params, String enc) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.HttpURLConnection;
import java.net.URL;

import java.net.URLEncoder;
import java.util.Map;

public class Main {
    public static boolean sendGetRequest(String path, Map<String, String> params, String enc) throws Exception {
        StringBuilder sb = new StringBuilder(path);
        sb.append('?');
        for (Map.Entry<String, String> entry : params.entrySet()) {
            sb.append(entry.getKey()).append('=').append(URLEncoder.encode(entry.getValue(), enc)).append('&');
        }/* ww  w . jav a2 s.  c om*/
        sb.deleteCharAt(sb.length() - 1);
        URL url = new URL(sb.toString());
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setConnectTimeout(5 * 1000);
        if (conn.getResponseCode() == 200) {
            return true;
        }
        return false;
    }
}

Related

  1. parse(final Map> parameters, final Scanner scanner, final String encoding)
  2. parse_parameters(String input)
  3. parseGetParameters(HttpExchange exchange)
  4. parseParameters(final String value)
  5. parseResponseParams(String body)
  6. sendPostRequest(String path, Map params, String enc)
  7. serializeParameters(final Map parameters)
  8. serializeParameters(final Map params)
  9. stringToMap(String input)