List of usage examples for org.apache.http.client.utils URLEncodedUtils format
public static String format(final Iterable<? extends NameValuePair> parameters, final Charset charset)
From source file:com.splunk.shuttl.server.mbeans.util.EndpointUtils.java
public static String createHttpGetParams(Object... kvs) { return URLEncodedUtils.format(createHttpParams(kvs), "utf-8"); }
From source file:nl.igorski.lib.utils.network.HTTPTransfer.java
private static String urlEncode(String aURL, List<NameValuePair> aParams) { return aParams == null ? aURL : aURL + "?" + URLEncodedUtils.format(aParams, "UTF-8"); }
From source file:Conexion.JSONParser.java
public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { // Making HTTP request try {/*from w ww . ja v a 2 s .c o m*/ // check for request method if (method == "POST") { // request method is POST // defaultHttpClient System.out.println("url es: " + url); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } else if (method == "GET") { // request method is GET DefaultHttpClient httpClient = new DefaultHttpClient(); String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n "); } is.close(); json = sb.toString(); System.out.println(json); } catch (Exception e) { System.out.println("Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); } catch (JSONException e) { System.out.println("Error parsing data " + e.toString()); } // return JSON String return jObj; }
From source file:com.chuck.core.filter.FilterQuery.java
/** * Builds a http get for the transitService specified * * @return returns the HTTP get// w ww . j av a 2 s. co m */ @Override public URI buildQuery() throws URISyntaxException { addParameter("api-key", TransitService.getApiKey()); return URIUtils.createURI("http", BASE_REQUEST_URL, 0, transitService.getServiceName(), URLEncodedUtils.format(parameters, "UTF-8"), null); }
From source file:com.lexicalintelligence.admin.add.AddRequest.java
public AddResponse execute() { List<BasicNameValuePair> params = Collections .singletonList(new BasicNameValuePair(getName(), StringUtils.join(items, ","))); AddResponse addResponse;// w ww. j a va2s . c o m Reader reader = null; try { HttpResponse response = client.getHttpClient().execute(new HttpGet(client.getUrl() + PATH + getPath() + "?" + URLEncodedUtils.format(params, StandardCharsets.UTF_8))); reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8); addResponse = new AddResponse(Boolean.valueOf(IOUtils.toString(reader))); } catch (Exception e) { addResponse = new AddResponse(false); log.error(e); } finally { try { reader.close(); } catch (Exception e) { log.error(e); } } return addResponse; }
From source file:com.lexicalintelligence.admin.remove.RemoveEntryRequest.java
@Override public RemoveResponse execute() { RemoveResponse removeResponse;/* ww w . j a v a 2 s . co m*/ List<BasicNameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("name", entry.getName())); params.add(new BasicNameValuePair("synonym", entry.getSynonym())); Reader reader = null; try { HttpResponse response = client.getHttpClient().execute(new HttpGet(client.getUrl() + PATH + getPath() + "?" + URLEncodedUtils.format(params, StandardCharsets.UTF_8))); reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8); removeResponse = new RemoveResponse(Boolean.valueOf(IOUtils.toString(reader))); } catch (Exception e) { removeResponse = new RemoveResponse(false); log.error(e); } finally { try { reader.close(); } catch (Exception e) { } } return removeResponse; }
From source file:org.ambraproject.wombat.util.UrlParamBuilder.java
public String format() { return URLEncodedUtils.format(params, Charsets.UTF_8).replace("%2F", "/"); }
From source file:com.lexicalintelligence.admin.remove.RemoveRequest.java
public RemoveResponse execute() { List<BasicNameValuePair> params = Collections .singletonList(new BasicNameValuePair(getName(), StringUtils.join(items, ","))); RemoveResponse removeResponse;//from ww w. j a v a 2 s .c om Reader reader = null; try { HttpResponse response = client.getHttpClient().execute(new HttpGet(client.getUrl() + PATH + getPath() + "?" + URLEncodedUtils.format(params, StandardCharsets.UTF_8))); reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8); removeResponse = new RemoveResponse(Boolean.valueOf(IOUtils.toString(reader))); } catch (Exception e) { removeResponse = new RemoveResponse(false); log.error(e); } finally { try { reader.close(); } catch (Exception e) { log.error(e); } } return removeResponse; }
From source file:org.apache.sling.testing.clients.util.URLParameterBuilder.java
/** * Build the URL parameters/* w w w . j av a 2 s . c o m*/ * * @return The URL parameters string without the leading question mark. */ public String getURLParameters() { return URLEncodedUtils.format(params, encoding); }
From source file:org.mobicents.servlet.sip.restcomm.interpreter.http.HttpRequestDescriptor.java
public HttpUriRequest getHttpRequest() throws IllegalArgumentException, URISyntaxException, UnsupportedEncodingException { if ("GET".equalsIgnoreCase(method)) { final String query = URLEncodedUtils.format(parameters, "UTF-8"); final URI uri = URIUtils.createURI(this.uri.getScheme(), this.uri.getHost(), this.uri.getPort(), this.uri.getPath(), query, null); return new HttpGet(uri); } else if ("POST".equalsIgnoreCase(method)) { final HttpPost post = new HttpPost(uri); post.setEntity(new UrlEncodedFormEntity(parameters)); return post; } else {// ww w. ja v a 2 s. c o m throw new IllegalArgumentException(method + " is not a supported HTTP method."); } }