List of usage examples for org.apache.http.client.methods HttpPost setEntity
public void setEntity(final HttpEntity entity)
From source file:org.fcrepo.camel.indexing.triplestore.integration.TestUtils.java
/** * Post data to the provided URL//w ww . j ava 2 s . c o m */ public static void httpPost(final String url, final String content, final String mimeType) throws Exception { final CloseableHttpClient httpClient = HttpClients.createDefault(); final HttpPost post = new HttpPost(url); post.addHeader(Exchange.CONTENT_TYPE, mimeType); post.setEntity(new StringEntity(content)); httpClient.execute(post); }
From source file:util.Slack.java
private static void sendMsg(StringEntity jsonMsg, String url) throws IOException { HttpClient httpClient = HttpClientBuilder.create().build(); //Use this instead try {/*from w ww.j a v a 2 s. c o m*/ HttpPost request = new HttpPost(url); request.addHeader("content-type", "application/json; charset=UTF-8"); request.setEntity(jsonMsg); HttpResponse response = httpClient.execute(request); System.out.println(response); } finally { httpClient.getConnectionManager().shutdown(); //Deprecated } }
From source file:de.intevation.irix.PrintClient.java
/** Obtains a Report from mapfish-print service. * * @param printUrl The url to send the request to. * @param json The json spec for the print request. * @param timeout the timeout for the httpconnection. * * @return byte[] with the report.//w ww. j a va2s.co m * * @throws IOException if communication with print service failed. * @throws PrintException if the print job failed. */ public static byte[] getReport(String printUrl, String json, int timeout) throws IOException, PrintException { RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout).build(); CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(config).build(); HttpEntity entity = new StringEntity(json, ContentType.create("application/json", Charset.forName("UTF-8"))); HttpPost post = new HttpPost(printUrl); post.setEntity(entity); CloseableHttpResponse resp = client.execute(post); StatusLine status = resp.getStatusLine(); byte[] retval = null; try { HttpEntity respEnt = resp.getEntity(); InputStream in = respEnt.getContent(); if (in != null) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[BYTE_ARRAY_SIZE]; int r; while ((r = in.read(buf)) >= 0) { out.write(buf, 0, r); } retval = out.toByteArray(); } finally { in.close(); EntityUtils.consume(respEnt); } } } finally { resp.close(); } if (status.getStatusCode() < HttpURLConnection.HTTP_OK || status.getStatusCode() >= HttpURLConnection.HTTP_MULT_CHOICE) { if (retval != null) { throw new PrintException(new String(retval)); } else { throw new PrintException("Communication with print service '" + printUrl + "' failed." + "\nNo response from print service."); } } return retval; }
From source file:org.fcrepo.auth.integration.AbstractResourceIT.java
protected static HttpPost postDSMethod(final String pid, final String ds, final String content) throws UnsupportedEncodingException { final HttpPost post = new HttpPost(serverAddress + pid + "/" + ds + "/jcr:content"); post.setEntity(new StringEntity(content)); return post;/*from w w w. ja v a 2s. com*/ }
From source file:org.lazydevs.api.gog.util.HttpClientUtil.java
public static HttpResponse post(HttpClient client, HttpContext context, String url, List<NameValuePair> params) { HttpPost post = new HttpPost(url); HttpResponse response;/*from www. j a v a2 s.c o m*/ post.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8)); try { response = client.execute(post, context); } catch (IOException e) { throw new GogApiException("Error executing POST request. url=" + url, e); } return response; }
From source file:com.firewallid.util.FIConnection.java
public static void sendJson(String host, String json) throws UnsupportedEncodingException, IOException { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(host); StringEntity input = new StringEntity(json); input.setContentType("application/json"); postRequest.setEntity(input); HttpResponse response = httpClient.execute(postRequest); }
From source file:org.apache.heron.integration_topology_test.core.HttpUtils.java
public static int httpJsonPost(String newHttpPostUrl, String jsonData) throws IOException, ParseException { HttpClient client = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(newHttpPostUrl); StringEntity requestEntity = new StringEntity(jsonData, ContentType.APPLICATION_JSON); post.setEntity(requestEntity); HttpResponse response = client.execute(post); return response.getStatusLine().getStatusCode(); }
From source file:org.mule.modules.quickbooks.api.gateway.oauth.OAuthGateway.java
public static String postUrlContentSigned(final OAuthConsumer consumer, final String url, final String content) { try {/*from w w w.j av a 2 s .co m*/ HttpPost request = new HttpPost(url); request.setEntity(new StringEntity(content)); consumer.sign(request); HttpResponse response = new DefaultHttpClient().execute(request); return parseContent(response); } catch (Exception e) { throw SoftException.soften(e); } }
From source file:Yak_Hax.Yak_Hax_Mimerme.PostRequest.java
public static String PostBodyRequest(String URL, String JSONRaw, TreeMap<String, String> headers) throws IOException { HttpPost post = new HttpPost(URL); HttpClient httpclient = HttpClients.custom().build(); post.setEntity(new StringEntity(JSONRaw)); post.setHeader("Content-Type", "application/json; charset=utf-8"); for (Map.Entry<String, String> entry : headers.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); post.setHeader(key, value);/* w w w . ja va 2 s.c o m*/ } HttpResponse response = httpclient.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } return result.toString(); }
From source file:org.fcrepo.integration.api.AbstractResourceIT.java
protected static HttpPost postDSMethod(final String pid, final String ds, final String content) throws UnsupportedEncodingException { final HttpPost post = new HttpPost(serverAddress + "objects/" + pid + "/datastreams/" + ds); post.setEntity(new StringEntity(content)); return post;//from w w w. j a va 2s.co m }